Class CsvSniffer
Infers a CSV dialect (delimiter, quote, encoding) from a sample of a delimited-text source.
public static class CsvSniffer
- Inheritance
-
CsvSniffer
- Inherited Members
Methods
Detect(Stream, CsvSnifferOptions?)
Reads a sample from the start of a seekable stream and infers its CSV dialect. The stream's position is restored before returning.
public static CsvDialect Detect(Stream stream, CsvSnifferOptions? options = null)
Parameters
streamStreamA seekable stream containing delimited-text data.
optionsCsvSnifferOptionsCandidate delimiters/quotes and the sample-line cap; Default when null.
Returns
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes not support seeking.
Detect(ReadOnlySpan<byte>, CsvSnifferOptions?)
Infers the dialect of a sample taken from the start of a delimited-text source.
public static CsvDialect Detect(ReadOnlySpan<byte> sample, CsvSnifferOptions? options = null)
Parameters
sampleReadOnlySpan<byte>A sample of bytes from the start of the source; only its first 64 KiB are examined.
optionsCsvSnifferOptionsCandidate delimiters/quotes and the sample-line cap; Default when null.
Returns
- CsvDialect
The inferred dialect, or Default when the sample does not allow a delimiter to be determined.
DetectAsync(Stream, CsvSnifferOptions?, CancellationToken)
Asynchronously reads a sample from the start of a seekable stream and infers its CSV dialect. The stream's position is restored before returning.
public static ValueTask<CsvDialect> DetectAsync(Stream stream, CsvSnifferOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamA seekable stream containing delimited-text data.
optionsCsvSnifferOptionsCandidate delimiters/quotes and the sample-line cap; Default when null.
ctCancellationTokenA token to cancel the read.
Returns
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes not support seeking.
DetectFile(string, CsvSnifferOptions?)
Reads a sample from the start of a file and infers its CSV dialect.
public static CsvDialect DetectFile(string path, CsvSnifferOptions? options = null)
Parameters
pathstringThe path to the delimited-text file.
optionsCsvSnifferOptionsCandidate delimiters/quotes and the sample-line cap; Default when null.
Returns
Exceptions
- ArgumentNullException
pathis null.
DetectFileAsync(string, CsvSnifferOptions?, CancellationToken)
Asynchronously reads a sample from the start of a file and infers its CSV dialect.
public static ValueTask<CsvDialect> DetectFileAsync(string path, CsvSnifferOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the delimited-text file.
optionsCsvSnifferOptionsCandidate delimiters/quotes and the sample-line cap; Default when null.
ctCancellationTokenA token to cancel the read.
Returns
Exceptions
- ArgumentNullException
pathis null.