Table of Contents

Utf8DotEnvWriter Struct

Definition

Namespace
Bodu.Text.DotEnv.Writer
Assembly
Bodu.Text.DotEnv.dll
Package
Bodu.Text.DotEnv 1.0.0
Source
Utf8DotEnvWriter.cs

Provides a high-performance, forward-only writer that emits DotEnv text as UTF-8 bytes to an IBufferWriter<T> or a Stream. The writer is a ref struct, so it lives on the stack and cannot be boxed or captured.

public ref struct Utf8DotEnvWriter
Inherited Members

Remarks

DotEnv is line-oriented, so the writer emits progressively: WritePropertyName(string) followed by WriteString(string) produces one KEY=VALUE line, and WriteComment(string) produces one # comment line. WriteStartObject() and WriteEndObject() frame the document to mirror the reader's token stream but emit no bytes of their own.

A value is emitted unquoted when it is safe to do so; a value that is empty is left after the =, and a value containing whitespace at its edges, an inline-comment sequence, a quote, a backslash, or a line break is double-quoted with the necessary escape sequences so a subsequent read round-trips it exactly.

Constructors

Utf8DotEnvWriter(IBufferWriter<byte>)

Initializes a new instance of the Utf8DotEnvWriter struct that writes to the supplied buffer.

public Utf8DotEnvWriter(IBufferWriter<byte> output)

Parameters

output IBufferWriter<byte>

The destination buffer writer.

Exceptions

ArgumentNullException

Thrown when output is null.

Utf8DotEnvWriter(IBufferWriter<byte>, DotEnvWriterOptions)

Initializes a new instance of the Utf8DotEnvWriter struct that writes to the supplied buffer using the supplied options.

public Utf8DotEnvWriter(IBufferWriter<byte> output, DotEnvWriterOptions options)

Parameters

output IBufferWriter<byte>

The destination buffer writer.

options DotEnvWriterOptions

The writer options.

Exceptions

ArgumentNullException

Thrown when output is null.

Utf8DotEnvWriter(Stream)

Initializes a new instance of the Utf8DotEnvWriter struct that writes to the supplied stream.

public Utf8DotEnvWriter(Stream stream)

Parameters

stream Stream

The destination stream.

Exceptions

ArgumentNullException

Thrown when stream is null.

Utf8DotEnvWriter(Stream, DotEnvWriterOptions)

Initializes a new instance of the Utf8DotEnvWriter struct that writes to the supplied stream using the supplied options.

public Utf8DotEnvWriter(Stream stream, DotEnvWriterOptions options)

Parameters

stream Stream

The destination stream.

options DotEnvWriterOptions

The writer options.

Exceptions

ArgumentNullException

Thrown when stream is null.

Properties

BytesCommitted

Gets the number of bytes flushed to the destination.

public readonly long BytesCommitted { get; }

Property Value

long

The committed byte count.

BytesPending

Gets the number of bytes written but not yet flushed to the destination.

public readonly long BytesPending { get; }

Property Value

long

The pending byte count; always zero in direct buffer-writer mode.

Methods

Dispose()

Flushes any buffered bytes and releases the writer.

public void Dispose()

Flush()

Flushes any buffered bytes to the destination stream. This method is a no-op in direct buffer-writer mode.

public void Flush()

WriteComment(string)

Writes a comment line prefixed with #, followed by a line feed.

public void WriteComment(string text)

Parameters

text string

The comment text, without the leading prefix.

Exceptions

ArgumentNullException

Thrown when text is null.

WriteEndObject()

Writes the document object end. DotEnv has no object delimiter, so this method emits no bytes; it exists to mirror the reader's token stream.

public readonly void WriteEndObject()

WritePropertyName(string)

Writes a key name, followed by the = assignment. Call WriteString(string) next to write the value.

public void WritePropertyName(string name)

Parameters

name string

The key name.

Remarks

The export prefix is emitted when WriteExportPrefix is set.

Exceptions

ArgumentNullException

Thrown when name is null.

WritePropertyName(string, bool)

Writes a key name with an explicit export decision, followed by the = assignment. Call WriteString(string) next to write the value.

public void WritePropertyName(string name, bool export)

Parameters

name string

The key name.

export bool

true to prefix the key with the export keyword.

Exceptions

ArgumentNullException

Thrown when name is null.

WriteStartObject()

Writes the document object start. DotEnv has no object delimiter, so this method emits no bytes; it exists to mirror the reader's token stream.

public readonly void WriteStartObject()

WriteString(string)

Writes a string value, quoting and escaping it when required, followed by a line feed.

public void WriteString(string value)

Parameters

value string

The value to write.

Exceptions

ArgumentNullException

Thrown when value is null.

Applies to

ProductVersions
.NET8, 10