Table of Contents

Bodu.Text.DotEnv.Writer Namespace

Package

Bodu.Text.DotEnv.Writer

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 struct writer: WriteStartObject / WriteEndObject framing, WritePropertyName (with an export overload) followed by WriteString for one KEY=value line, WriteComment, plus Flush, Dispose, BytesCommitted, and BytesPending.
  • DotEnvWriterOptions - WriteExportPrefix, the default export policy applied by the single-argument WritePropertyName.

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 / WriteEndObject mirror 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 (or Dispose).
  • 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.