Bodu.Text.DotEnv.Reader Namespace
- Package
-
Bodu.Text.DotEnv 1.0.0
Purpose
Bodu.Text.DotEnv.Reader is the lowest tier of Bodu.Text.DotEnv: a forward-only token reader over UTF-8 .env text that handles the export prefix, single- and double-quoted values with escapes, and full-line and inline comments. The DotEnvSerializer, the mutable DotEnvNode DOM, and the read-only DotEnvDocument DOM are all built over it.
Key types
- Utf8DotEnvReader - the
ref structcursor:Read/Skip/TrySkip,TokenType(a DotEnvTokenType),ValueSpan/GetString,ValueTextEquals,CurrentIsExport,LineNumber,CurrentDepth, andBytesConsumed. - DotEnvReaderOptions -
DisallowExportPrefix,DisallowInlineComments, andSkipComments.
Example
using Bodu.Text.DotEnv;
using Bodu.Text.DotEnv.Reader;
var reader = new Utf8DotEnvReader("export APP_ENV=production\nAPP_PORT=8080 # inline\n"u8);
while (reader.Read())
{
if (reader.TokenType == DotEnvTokenType.PropertyName)
Console.WriteLine($"{reader.GetString()} (export: {reader.CurrentIsExport})");
}
Notes
- One flat object. The stream is
StartObject, thenPropertyName/Stringpairs (withCommenttokens unlessSkipComments), thenEndObject; there is no nesting. - Literal values. Quoting and escapes are decoded, but
${VAR}interpolation is never performed - what the file says is what you get. - Malformed input throws DotEnvFormatException.
- See also: the line-formats introduction and the DotEnv guide.
Structs
- DotEnvReaderOptions
Provides configuration for a Utf8DotEnvReader, controlling how the reader interprets optional DotEnv syntax conventions.
- Utf8DotEnvReader
Provides a high-performance, forward-only, allocation-light reader for DotEnv bytes. The reader is a
ref struct, so it lives on the stack and cannot be boxed or captured; pass it by ref to thread it through a converter.