cassava-streams-0.1.0.0: io-streams interface for the cassava CSV library.

Safe HaskellNone

System.IO.Streams.Csv

Contents

Description

This module exports functions which can be used to read instances of the cassava classes FromRecord and FromNamedRecord from an io-streams InputStream ByteString.

It also exports functions which can write instances of ToRecord and ToNamedRecord to an io-streams OutputStream ByteString.

See the System.IO.Streams.Csv.Tutorial module for a simple tutorial.

Synopsis

Decoding CSV

These functions convert an io-streams InputStream ByteString stream into one that decodes CSV records and produces these decoded records.

Each of the decoding functions produce an InputStream which yields an Either value. Left String represents a record which failed type conversion. Right a is a successfully decoded record.

See the tutorial in System.IO.Streams.Csv.Tutorial for details on how to use the onlyValidRecords function to transform the decoding streams so that they only produce valid records and throw exceptions for bad records.

data StreamDecodingError Source

Exception thrown when stream decoding cannot continue due to an error.

decodeStreamSource

Arguments

:: FromRecord a 
=> HasHeader

Whether to skip a header or not.

-> InputStream ByteString

Upstream.

-> IO (InputStream (Either String a))

An InputStream which produces records.

Create an InputStream which decodes CSV records from the given upstream data source.

Equivalent to decodeStreamWith defaultDecodeOptions.

decodeStreamWithSource

Arguments

:: FromRecord a 
=> DecodeOptions

CSV decoding options.

-> HasHeader

Whether to skip a header or not.

-> InputStream ByteString

Upstream.

-> IO (InputStream (Either String a))

An InputStream which produces records.

Create an InputStream which decodes CSV records from the given upstream data source.

decodeStreamByNameSource

Arguments

:: FromNamedRecord a 
=> InputStream ByteString

Upstream.

-> IO (InputStream (Either String a))

An InputStream which produces records.

Create an InputStream which decodes CSV records from the given upstream data source. Data should be preceded by a header.

Equivalent to decodeStreamByNameWith defaultDecodeOptions.

decodeStreamByNameWithSource

Arguments

:: FromNamedRecord a 
=> DecodeOptions

CSV decoding options.

-> InputStream ByteString

Upstream.

-> IO (InputStream (Either String a))

An InputStream which produces records.

Create an InputStream which decodes CSV records from the given upstream data source. Data should be preceded by a header.

onlyValidRecordsSource

Arguments

:: InputStream (Either String a)

Upstream.

-> IO (InputStream a)

An InputStream which only produces valid records.

Creates a new InputStream which only sends valid CSV records downstream. The first invalid record will throw an exception.

Encoding CSV

These functions convert an io-streams OutputStream ByteString stream into one that encodes records into CSV format before sending them downstream.

encodeStreamSource

Arguments

:: ToRecord a 
=> OutputStream ByteString

Downstream.

-> IO (OutputStream a)

New OutputStream.

Create a new OutputStream that can be fed ToRecord values which are converted to CSV. The records are encoded into ByteStrings and passed on to the given downstream OutputStream.

Equivalent to encodeStreamWith defaultEncodeOptions.

encodeStreamWithSource

Arguments

:: ToRecord a 
=> EncodeOptions

Encoding options.

-> OutputStream ByteString

Downstream.

-> IO (OutputStream a)

New OutputStream.

Create a new OutputStream that can be fed ToRecord values which are converted to CSV. The records are encoded into ByteStrings and passed on to the given downstream OutputStream.

encodeStreamByNameSource

Arguments

:: ToNamedRecord a 
=> Header

CSV Header.

-> OutputStream ByteString

Downstream.

-> IO (OutputStream a)

New OutputStream.

Create a new OutputStream which can be fed ToNamedRecord values that will be converted into CSV. The records are encoded into ByteStrings and passed on to the given downstream OutputStream.

Equivalent to encodeStreamByNameWith defaultEncodeOptions.

encodeStreamByNameWithSource

Arguments

:: ToNamedRecord a 
=> EncodeOptions

Encoding options.

-> Header

CSV Header.

-> OutputStream ByteString

Downstream.

-> IO (OutputStream a)

New OutputStream.

Create a new OutputStream which can be fed ToNamedRecord values that will be converted into CSV. The records are encoded into ByteStrings and passed on to the given downstream OutputStream.