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
-
objectCsv
Methods
From(Stream, CsvIOOptions)
Creates a reader builder from the given Stream.
public static Csv.IReadStreamBuilder From(Stream stream, CsvIOOptions ioOptions = default)
Parameters
streamStreamStream to read the CSV data from
ioOptionsCsvIOOptionsOptions 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
streamStreamStream to read the CSV data from
encodingEncodingEncoding of the stream, defaults to UTF8
ioOptionsCsvIOOptionsOptions 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
readerTextReaderReader to read the CSV data from
ioOptionsCsvIOOptionsOptions 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
csvReadOnlyMemory<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
csvReadOnlyMemory<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
csvstringCSV 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
csvStringBuilderCSV data
ioOptionsCsvIOOptionsOptions 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
pathstringPath to the file to read the CSV data from
ioOptionsCsvIOOptionsOptions 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
pathstringPath to the file to read the CSV data from
encodingEncodingEncoding of the stream, defaults to UTF8
ioOptionsCsvIOOptionsOptions 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
csvReadOnlySequence<T>CSV data
ioOptionsCsvIOOptionsOptions 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
pipeWriterPipeWriterPipeWriter 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
streamStreamStream to write the CSV data to
ioOptionsCsvIOOptionsOptions 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
streamStreamStream to write the CSV data to
encodingEncodingEncoding of the stream, defaults to UTF8
ioOptionsCsvIOOptionsOptions 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
writerTextWriterWriter to write the CSV data to
ioOptionsCsvIOOptionsOptions 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
stringBuilderStringBuilderStringBuilder to write the CSV data to
ioOptionsCsvIOOptionsOptions 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
pathstringPath to the file to write the CSV data to
ioOptionsCsvIOOptionsOptions 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
pathstringPath to the file to write the CSV data to
encodingEncodingEncoding of the file, defaults to UTF8
ioOptionsCsvIOOptionsOptions 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
bufferWriterIBufferWriter<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.