Table of Contents

Bodu.Text.Ini.Writer Namespace

Package

Bodu.Text.Ini.Writer

Purpose

Bodu.Text.Ini.Writer is the emitting counterpart of Bodu.Text.Ini.Reader in Bodu.Text.Ini: a forward-only writer that produces INI text as UTF-8 into an IBufferWriter<byte> or a Stream, one line per call. The IniSerializer and the comment-preserving IniNode DOM (WriteTo) emit through it.

Key types

  • Utf8IniWriter - the ref struct writer: WriteSectionHeader for a [name] line, WritePropertyName followed by WriteString for one key=value line, WriteComment for a comment line, plus Flush, Dispose, BytesCommitted, and BytesPending.
  • IniWriterOptions - CommentPrefix, the character (; by default) placed before comment text.

Example

using System.Buffers;
using Bodu.Text.Ini.Writer;

var buffer = new ArrayBufferWriter<byte>();
var writer = new Utf8IniWriter(buffer, new IniWriterOptions { CommentPrefix = '#' });

writer.WriteComment("generated by deploy");
writer.WriteSectionHeader("server");
writer.WritePropertyName("host");
writer.WriteString("localhost");
writer.WritePropertyName("port");
writer.WriteString("8080");
writer.Flush();
// # generated by deploy
// [server]
// host=localhost
// port=8080

Notes

  • Global entries first. Any WritePropertyName / WriteString pair before the first WriteSectionHeader lands in the global (section-less) area.
  • Literal values. Values are written verbatim to end of line - there is no quoting layer in the INI dialect, so a value must not contain a line break.
  • Flush to commit. Bytes are staged until Flush (or Dispose).
  • See also: the line-formats introduction and the INI guide.

Structs

IniWriterOptions

Provides configuration for a Utf8IniWriter, controlling the comment prefix.

Utf8IniWriter

Provides a forward-only writer that emits INI text as UTF-8 bytes to an IBufferWriter<T> or a Stream. The writer is a ref struct.