Utf8DelimitedWriter Struct
Definition
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.
public ref struct Utf8DelimitedWriter
- Inherited Members
Remarks
Records are written between WriteStartArray() and WriteEndArray(). An object record - WriteStartObject(), WritePropertyName(string) / WriteString(string) pairs, then WriteEndObject() - contributes a header row (from the first record's names) followed by a value row. A positional record - a nested WriteStartArray() of WriteString(string) values - contributes a value row with no header.
Fields that contain the delimiter, the quote character, or a line break are automatically quoted, with internal quotes doubled, so the output round-trips through Utf8DelimitedReader.
Constructors
Utf8DelimitedWriter(IBufferWriter<byte>)
Initializes a new instance of the Utf8DelimitedWriter struct that writes to the supplied buffer.
public Utf8DelimitedWriter(IBufferWriter<byte> output)
Parameters
outputIBufferWriter<byte>The destination buffer writer.
Exceptions
- ArgumentNullException
Thrown when
outputis null.
Utf8DelimitedWriter(IBufferWriter<byte>, DelimitedWriterOptions)
Initializes a new instance of the Utf8DelimitedWriter struct that writes to the supplied buffer using the supplied options.
public Utf8DelimitedWriter(IBufferWriter<byte> output, DelimitedWriterOptions options)
Parameters
outputIBufferWriter<byte>The destination buffer writer.
optionsDelimitedWriterOptionsThe writer options.
Exceptions
- ArgumentNullException
Thrown when
outputis null.
Utf8DelimitedWriter(Stream)
Initializes a new instance of the Utf8DelimitedWriter struct that writes to the supplied stream.
public Utf8DelimitedWriter(Stream stream)
Parameters
streamStreamThe destination stream.
Exceptions
- ArgumentNullException
Thrown when
streamis null.
Utf8DelimitedWriter(Stream, DelimitedWriterOptions)
Initializes a new instance of the Utf8DelimitedWriter struct that writes to the supplied stream using the supplied options.
public Utf8DelimitedWriter(Stream stream, DelimitedWriterOptions options)
Parameters
streamStreamThe destination stream.
optionsDelimitedWriterOptionsThe writer options.
Exceptions
- ArgumentNullException
Thrown when
streamis 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()
WriteEndArray()
Writes the end of the document array, or flushes a positional record when inside the document.
public void WriteEndArray()
WriteEndObject()
Writes the end of an object record, emitting the header row on the first record.
public void WriteEndObject()
WritePropertyName(string)
Writes the name of the next field within an object record.
public readonly void WritePropertyName(string name)
Parameters
namestringThe field name.
Exceptions
- ArgumentNullException
Thrown when
nameis null.
WriteStartArray()
Writes the start of the document array, or the start of a positional record when already inside the document.
public void WriteStartArray()
WriteStartObject()
Writes the start of an object record.
public void WriteStartObject()
WriteString(string)
Writes the value of the next field.
public readonly void WriteString(string value)
Parameters
valuestringThe field value.
Exceptions
- ArgumentNullException
Thrown when
valueis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |