pipes-csv-1.4.0: Fast, streaming csv parser

Safe HaskellNone
LanguageHaskell2010

Pipes.Csv

Contents

Description

This module allows constant-space CSV parsing.

It feeds ByteStrings into cassavas incremental CSV parser to attain true constant-space record streaming.

Synopsis

Example

Heres a simple example that reads from stdin and writes to a file

@ import Pipes.Safe (runSafeT) import qualified Pipes.Safe.Prelude as PS import qualified Pipes.ByteString as PB import Data.Vector (fromList) import System.IO (IOMode(WriteMode))

data Person = Person String Int deriving (Show)

instance FromNamedRecord Person where parseNamedRecord p = Person <$> p .: "name" <*> p .: "age"

personRec ~(Person name age) = ["name" .= name, "age" .= age]

instance ToNamedRecord Person where toNamedRecord = namedRecord . personRec

persons :: Monad m => Producer ByteString m () -> Producer Person m () persons p = decodeByName p >-> right

Decode records

decodeWith :: (Monad m, FromRecord a) => DecodeOptions -> HasHeader -> Producer ByteString m () -> Producer (Either String a) m () Source

Create a Producer that takes a ByteString Producer as input, producing either errors or FromRecords.

Decode named records

decodeByNameWith :: (Monad m, FromNamedRecord a) => DecodeOptions -> Producer ByteString m () -> Producer (Either String a) m () Source

Create a Producer that takes a ByteString Producer as input, producing either errors or FromNamedRecords.

Decode parsed records

feedParser :: Monad m => Parser a -> Producer ByteString m () -> Producer (Either String a) m () Source

Create a Record Producer by feeding ByteStrings into a Parser

feedHeaderParser :: Monad m => HeaderParser (Parser a) -> Producer ByteString m () -> Producer (Either String a) m () Source

Create a NamedRecord Producer by feeding ByteStrings into a Parser

Encode records

encode :: (Monad m, ToRecord a) => Pipe a ByteString m r Source

Encode records as strict ByteStrings

encodeWith :: (Monad m, ToRecord a) => EncodeOptions -> Pipe a ByteString m r Source

Encode records as strict ByteStrings

Encode named records

encodeByName :: (Monad m, ToNamedRecord a) => Header -> Pipe a ByteString m r Source

Encode named records as strict ByteStrings

encodeByNameWith :: (Monad m, ToNamedRecord a) => EncodeOptions -> Header -> Pipe a ByteString m r Source

Encode named records as strict ByteStrings

Re-exports

module Data.Csv

data HasHeader :: *

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