Table of Contents

Class CsvSniffer

Namespace
ExcelReader.Core.Reader.Csv
Assembly
ExcelReader.Core.dll

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

stream Stream

A seekable stream containing delimited-text data.

options CsvSnifferOptions

Candidate delimiters/quotes and the sample-line cap; Default when null.

Returns

CsvDialect

Exceptions

ArgumentNullException

stream is null.

ArgumentException

stream does 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

sample ReadOnlySpan<byte>

A sample of bytes from the start of the source; only its first 64 KiB are examined.

options CsvSnifferOptions

Candidate 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

stream Stream

A seekable stream containing delimited-text data.

options CsvSnifferOptions

Candidate delimiters/quotes and the sample-line cap; Default when null.

ct CancellationToken

A token to cancel the read.

Returns

ValueTask<CsvDialect>

Exceptions

ArgumentNullException

stream is null.

ArgumentException

stream does 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

path string

The path to the delimited-text file.

options CsvSnifferOptions

Candidate delimiters/quotes and the sample-line cap; Default when null.

Returns

CsvDialect

Exceptions

ArgumentNullException

path is 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

path string

The path to the delimited-text file.

options CsvSnifferOptions

Candidate delimiters/quotes and the sample-line cap; Default when null.

ct CancellationToken

A token to cancel the read.

Returns

ValueTask<CsvDialect>

Exceptions

ArgumentNullException

path is null.