cassava-0.4.2.0: A CSV parsing and encoding library

Safe HaskellNone
LanguageHaskell98

Data.Csv.Incremental

Contents

Description

This module allows for incremental decoding of CSV data. This is useful if you e.g. want to interleave I/O with parsing or if you want finer grained control over how you deal with type conversion errors.

Synopsis

Decoding headers

data HeaderParser a Source

An incremental parser that when fed data eventually returns a parsed Header, or an error.

Constructors

FailH !ByteString String

The input data was malformed. The first field contains any unconsumed input and second field contains information about the parse error.

PartialH (ByteString -> HeaderParser a)

The parser needs more input data before it can produce a result. Use an empty string to indicate that no more input data is available. If fed an 'B.empty string', the continuation is guaranteed to return either FailH or DoneH.

DoneH !Header a

The parse succeeded and produced the given Header.

decodeHeader :: HeaderParser ByteString Source

Parse a CSV header in an incremental fashion. When done, the HeaderParser returns any unconsumed input in the second field of the DoneH constructor.

decodeHeaderWith :: DecodeOptions -> HeaderParser ByteString Source

Like decodeHeader, but lets you customize how the CSV data is parsed.

Decoding records

Just like in the case of non-incremental decoding, there are two ways to convert CSV records to and from and user-defined data types: index-based conversion and name-based conversion.

data Parser a Source

An incremental parser that when fed data eventually produces some parsed records, converted to the desired type, or an error in case of malformed input data.

Constructors

Fail !ByteString String

The input data was malformed. The first field contains any unconsumed input and second field contains information about the parse error.

Many [Either String a] (ByteString -> Parser a)

The parser parsed and converted zero or more records. Any records that failed type conversion are returned as Left errMsg and the rest as Right val. Feed a ByteString to the continuation to continue parsing. Use an empty string to indicate that no more input data is available. If fed an empty string, the continuation is guaranteed to return either Fail or Done.

Done [Either String a]

The parser parsed and converted some records. Any records that failed type conversion are returned as Left errMsg and the rest as Right val.

Instances

Index-based record conversion

See documentation on index-based conversion in Data.Csv for more information.

data HasHeader Source

Is the CSV data preceded by a header?

Constructors

HasHeader

The CSV data is preceded by a header

NoHeader

The CSV data is not preceded by a header

decode Source

Arguments

:: FromRecord a 
=> HasHeader

Data contains header that should be skipped

-> Parser a 

Efficiently deserialize CSV in an incremental fashion. Equivalent to decodeWith defaultDecodeOptions.

decodeWith Source

Arguments

:: FromRecord a 
=> DecodeOptions

Decoding options

-> HasHeader

Data contains header that should be skipped

-> Parser a 

Like decode, but lets you customize how the CSV data is parsed.

Name-based record conversion

See documentation on name-based conversion in Data.Csv for more information.

decodeByName :: FromNamedRecord a => HeaderParser (Parser a) Source

Efficiently deserialize CSV in an incremental fashion. The data is assumed to be preceeded by a header. Returns a HeaderParser that when done produces a Parser for parsing the actual records. Equivalent to decodeByNameWith defaultDecodeOptions.

decodeByNameWith Source

Arguments

:: FromNamedRecord a 
=> DecodeOptions

Decoding options

-> HeaderParser (Parser a) 

Like decodeByName, but lets you customize how the CSV data is parsed.