Bodu.Text.Delimited.Writer Namespace
- Package
-
Bodu.Text.Delimited 1.0.0
Purpose
Bodu.Text.Delimited.Writer is the emitting counterpart of Bodu.Text.Delimited.Reader in Bodu.Text.Delimited: a forward-only writer that produces RFC 4180 delimited text as UTF-8 into an IBufferWriter<byte> or a Stream. The DelimitedSerializer and the mutable DelimitedNode DOM (WriteTo) emit through it.
Key types
- Utf8DelimitedWriter - the
ref structwriter:WriteStartArray/WriteEndArrayaround the record set,WriteStartObject/WritePropertyName/WriteString/WriteEndObjectfor header-keyed records (or a nested array ofWriteStringfor positional rows), plusFlush,Dispose,BytesCommitted, andBytesPending. - DelimitedWriterOptions -
Delimiter,Quote, andNoHeader.
Example
using System.Buffers;
using Bodu.Text.Delimited.Writer;
var buffer = new ArrayBufferWriter<byte>();
var writer = new Utf8DelimitedWriter(buffer, new DelimitedWriterOptions { Delimiter = '\t' });
writer.WriteStartArray();
writer.WriteStartObject();
writer.WritePropertyName("symbol");
writer.WriteString("AAPL");
writer.WritePropertyName("qty");
writer.WriteString("10");
writer.WriteEndObject();
writer.WriteEndArray();
writer.Flush(); // "symbol\tqty\nAAPL\t10\n"
Notes
- Header from the first record. The property names of the first object record become the header row; subsequent records contribute value rows only.
- Minimal quoting. A field is quoted only when it contains the delimiter, the quote character, or a line break, with internal quotes doubled, so output round-trips through the reader.
- Flush to commit. Bytes are staged until
Flush(orDispose); checkBytesPendingto see what is still buffered. - See also: the line-formats introduction and the delimited guide.
Structs
- DelimitedWriterOptions
Provides configuration for a Utf8DelimitedWriter, controlling the delimiter, quote character, and whether a header row is emitted for object records.
- Utf8DelimitedWriter
Provides a forward-only writer that emits delimited (RFC 4180 CSV/TSV) text as UTF-8 bytes to an IBufferWriter<T> or a Stream. The writer is a
ref struct.