Table of Contents

Class Csv

Namespace
FlameCsv
Assembly
FlameCsv.Core.dll

Provides static methods to read and write CSV.
To read CSV, see From and FromFile methods.
To write CSV, see To and ToFile methods.

public static class Csv
Inheritance
object
Csv

Methods

From(Stream, CsvIOOptions)

Creates a reader builder from the given Stream.

public static Csv.IReadStreamBuilder From(Stream stream, CsvIOOptions ioOptions = default)

Parameters

stream Stream

Stream to read the CSV data from

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadStreamBuilder

Builder to create a CSV reading pipeline from

Remarks

This method reads the bytes directly as UTF8. To work with char, see From(Stream, Encoding?, CsvIOOptions) or WithEncoding(Encoding).

From(Stream, Encoding?, CsvIOOptions)

Creates a reader builder from the given Stream in the specified encoding.

public static Csv.IReadBuilder<char> From(Stream stream, Encoding? encoding, CsvIOOptions ioOptions = default)

Parameters

stream Stream

Stream to read the CSV data from

encoding Encoding

Encoding of the stream, defaults to UTF8

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadBuilder<char>

Builder to create a CSV reading pipeline from

From(TextReader, CsvIOOptions)

Creates a reader builder from the given TextReader.

public static Csv.IReadBuilder<char> From(TextReader reader, CsvIOOptions ioOptions = default)

Parameters

reader TextReader

Reader to read the CSV data from

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadBuilder<char>

Builder to create a CSV reading pipeline from

From(ReadOnlyMemory<byte>)

Creates a reader builder from the given CSV data.

public static Csv.IReadBuilder<byte> From(ReadOnlyMemory<byte> csv)

Parameters

csv ReadOnlyMemory<byte>

CSV data

Returns

Csv.IReadBuilder<byte>

Builder to create a CSV reading pipeline from

From(ReadOnlyMemory<char>)

Creates a reader builder from the given CSV data.

public static Csv.IReadBuilder<char> From(ReadOnlyMemory<char> csv)

Parameters

csv ReadOnlyMemory<char>

CSV data

Returns

Csv.IReadBuilder<char>

Builder to create a CSV reading pipeline from

From(string?)

Creates a reader builder from the given CSV data.

public static Csv.IReadBuilder<char> From(string? csv)

Parameters

csv string

CSV data

Returns

Csv.IReadBuilder<char>

Builder to create a CSV reading pipeline from

From(StringBuilder, CsvIOOptions)

Creates a reader builder from the given CSV data.

public static Csv.IReadBuilder<char> From(StringBuilder csv, CsvIOOptions ioOptions = default)

Parameters

csv StringBuilder

CSV data

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadBuilder<char>

Builder to create a CSV reading pipeline from

Remarks

The StringBuilder must not be modified while the reader is in use.

FromFile(string, CsvIOOptions)

Creates a reader builder from the given file.

public static Csv.IReadStreamBuilder FromFile(string path, CsvIOOptions ioOptions = default)

Parameters

path string

Path to the file to read the CSV data from

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadStreamBuilder

Builder to create a CSV reading pipeline from

Remarks

This method reads the bytes directly as UTF8. To work with char, see FromFile(string, Encoding?, CsvIOOptions) or WithEncoding(Encoding).

FromFile(string, Encoding?, CsvIOOptions)

Creates a reader builder from the given file using the specified encoding.

public static Csv.IReadBuilder<char> FromFile(string path, Encoding? encoding, CsvIOOptions ioOptions = default)

Parameters

path string

Path to the file to read the CSV data from

encoding Encoding

Encoding of the stream, defaults to UTF8

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadBuilder<char>

Builder to create a CSV reading pipeline from

From<T>(in ReadOnlySequence<T>, CsvIOOptions)

Creates a reader builder from the given CSV data.

public static Csv.IReadBuilder<T> From<T>(in ReadOnlySequence<T> csv, CsvIOOptions ioOptions = default) where T : unmanaged, IBinaryInteger<T>

Parameters

csv ReadOnlySequence<T>

CSV data

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IReadBuilder<T>

Builder to create a CSV reading pipeline from

Type Parameters

T

Remarks

Parallel reading from a sequence is not yet supported.

To(PipeWriter)

Creates a writer builder from the given CSV data.

public static Csv.IWriteBuilder<byte> To(PipeWriter pipeWriter)

Parameters

pipeWriter PipeWriter

PipeWriter to write the CSV data to

Returns

Csv.IWriteBuilder<byte>

Builder to create a CSV writing pipeline from

Remarks

PipeWriter does not support synchronous flushing. Only buffer pool is configurable via CsvIOOptions, buffer sizes should be configured to the pipe itself.

To(Stream, CsvIOOptions)

Creates a writer builder from the given CSV data.

public static Csv.IWriteStreamBuilder To(Stream stream, CsvIOOptions ioOptions = default)

Parameters

stream Stream

Stream to write the CSV data to

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IWriteStreamBuilder

Builder to create a CSV writing pipeline from

Remarks

This method writes bytes directly as UTF8. To work with char, see ToFile(string, Encoding?, CsvIOOptions) or WithEncoding(Encoding).

To(Stream, Encoding?, CsvIOOptions)

Creates a writer builder from the given CSV data.

public static Csv.IWriteBuilder<char> To(Stream stream, Encoding? encoding, CsvIOOptions ioOptions = default)

Parameters

stream Stream

Stream to write the CSV data to

encoding Encoding

Encoding of the stream, defaults to UTF8

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IWriteBuilder<char>

Builder to create a CSV writing pipeline from

To(TextWriter, CsvIOOptions)

Creates a writer builder from the given CSV data.

public static Csv.IWriteBuilder<char> To(TextWriter writer, CsvIOOptions ioOptions = default)

Parameters

writer TextWriter

Writer to write the CSV data to

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IWriteBuilder<char>

Builder to create a CSV writing pipeline from

To(StringBuilder, CsvIOOptions)

Creates a writer builder from the given CSV data.

public static Csv.IWriteBuilder<char> To(StringBuilder stringBuilder, CsvIOOptions ioOptions = default)

Parameters

stringBuilder StringBuilder

StringBuilder to write the CSV data to

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IWriteBuilder<char>

Builder to create a CSV writing pipeline from

ToFile(string, CsvIOOptions)

Creates a writer builder to write CSV data to a file.

public static Csv.IWriteStreamBuilder ToFile(string path, CsvIOOptions ioOptions = default)

Parameters

path string

Path to the file to write the CSV data to

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IWriteStreamBuilder

Builder to create a CSV writing pipeline from

Remarks

This method writes bytes directly as UTF8. To work with char, see ToFile(string, Encoding?, CsvIOOptions) or WithEncoding(Encoding).

ToFile(string, Encoding?, CsvIOOptions)

Creates a writer builder to write CSV data to a file using the specified encoding.

public static Csv.IWriteBuilder<char> ToFile(string path, Encoding? encoding, CsvIOOptions ioOptions = default)

Parameters

path string

Path to the file to write the CSV data to

encoding Encoding

Encoding of the file, defaults to UTF8

ioOptions CsvIOOptions

Options to configure the buffer size and other IO related options

Returns

Csv.IWriteBuilder<char>

Builder to create a CSV writing pipeline from

To<T>(IBufferWriter<T>)

Creates a writer builder from the given CSV data.

public static Csv.IWriteBuilder<T> To<T>(IBufferWriter<T> bufferWriter) where T : unmanaged, IBinaryInteger<T>

Parameters

bufferWriter IBufferWriter<T>

Buffer writer to write the CSV data to

Returns

Csv.IWriteBuilder<T>

Builder to create a CSV writing pipeline from

Type Parameters

T

Remarks

As buffer writer does not support flushing, all data is written directly to the writer. As such, async doesn't provide any benefit over with this type.
Only buffer pool is configurable via CsvIOOptions.