Bodu.Text.DotEnv.Writer Namespace
- Package
-
Bodu.Text.DotEnv 1.0.0
Purpose
Bodu.Text.DotEnv.Writer is the emitting counterpart of Bodu.Text.DotEnv.Reader in Bodu.Text.DotEnv: a forward-only writer that produces .env text as UTF-8 into an IBufferWriter<byte> or a Stream, quoting values only when required. The DotEnvSerializer and the mutable DotEnvNode DOM (WriteTo) emit through it.
Key types
- Utf8DotEnvWriter - the
ref structwriter:WriteStartObject/WriteEndObjectframing,WritePropertyName(with anexportoverload) followed byWriteStringfor oneKEY=valueline,WriteComment, plusFlush,Dispose,BytesCommitted, andBytesPending. - DotEnvWriterOptions -
WriteExportPrefix, the defaultexportpolicy applied by the single-argumentWritePropertyName.
Example
using System.Buffers;
using Bodu.Text.DotEnv.Writer;
var buffer = new ArrayBufferWriter<byte>();
var writer = new Utf8DotEnvWriter(buffer);
writer.WriteStartObject();
writer.WriteComment("generated by deploy");
writer.WritePropertyName("APP_ENV", export: true);
writer.WriteString("production");
writer.WritePropertyName("APP_PORT");
writer.WriteString("8080");
writer.WriteEndObject();
writer.Flush();
// # generated by deploy
// export APP_ENV=production
// APP_PORT=8080
Notes
- Line-oriented and progressive. Each name/value pair or comment is emitted as its own line;
WriteStartObject/WriteEndObjectmirror the reader's tokens but emit no bytes. - Quoting is automatic. A value with leading/trailing whitespace, a
#sequence, a quote, a backslash, or a line break is double-quoted with escapes so it reads back exactly. - Flush to commit. Bytes are staged until
Flush(orDispose). - See also: the line-formats introduction and the DotEnv guide.
Structs
- DotEnvWriterOptions
Provides configuration for a Utf8DotEnvWriter, controlling how entries are emitted.
- Utf8DotEnvWriter
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.