-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A flexible, fast, enumerator-based CSV parser library for Haskell. -- -- CSV files are the de-facto standard in many situations involving data -- transfer, particularly when dealing with enterprise application or -- disparate database systems. -- -- While there are a number of CSV libraries in Haskell, at the time of -- this project's start in 2010, there wasn't one that provided all of -- the following: -- --
-- csvSep = ',' -- csvQuoteChar = Just '"' -- csvOutputQuoteChar = Just '"' -- csvOutputColSep = ',' --defCSVSettings :: CSVSettings readCSVFile :: CSVeable r => CSVSettings -> FilePath -> IO (Either SomeException [r]) writeCSVFile :: CSVeable r => CSVSettings -> FilePath -> [r] -> IO Int appendCSVFile :: CSVeable r => CSVSettings -> FilePath -> [r] -> IO Int -- | Open & fold over the CSV file. -- -- Processing starts on row 2 for MapRow instance to use first row as -- column headers. foldCSVFile :: CSVeable r => FilePath -> CSVSettings -> CSVAction r a -> a -> IO (Either SomeException a) -- | An iteratee that processes each row of a CSV file and updates the -- accumulator. -- -- You would implement one of these to use with the foldCSVFile -- function. type CSVAction r a = a -> ParsedRow r -> Iteratee ByteString IO a -- | Convenience converter for fold step functions that are pure. -- -- Use this if you don't want to deal with Iteratees when writing your -- fold functions. funToIter :: CSVeable r => (a -> ParsedRow r -> a) -> CSVAction r a -- | Convenience converter for fold step functions that live in the IO -- monad. -- -- Use this if you don't want to deal with Iteratees when writing your -- fold functions. funToIterIO :: CSVeable r => (a -> ParsedRow r -> IO a) -> CSVAction r a -- | Take a CSV file, apply function to each of its rows and save the -- resulting rows into a new file. -- -- Each row is simply a list of fields. mapCSVFile :: CSVeable r => FilePath -> CSVSettings -> (r -> [r]) -> FilePath -> IO (Either SomeException Int) -- | Create an iteratee that can map over a CSV stream and output results -- to a handle in an interleaved fashion. -- -- Example use: Let's map over a CSV file coming in through stdin -- and push results to stdout. -- --
-- f r = return [r] -- a function that just returns the given row ---- --
-- E.run (E.enumHandle 4096 stdin $$ mapIntoHandle defCSVSettings True stdout f) ---- -- This nicely allows us to do things like (assuming you have pv -- installed): -- --
-- pv inputFile.csv | myApp > output.CSV ---- -- And monitor the ongoing progress of processing. mapIntoHandle :: CSVeable r => CSVSettings -> Bool -> Handle -> (r -> IO [r]) -> Iteratee ByteString IO Int -- | Just collect all rows into an array. This will cancel out the -- incremental nature of this library. collectRows :: CSVeable r => CSVAction r [r] outputRowIter :: CSVeable r => CSVSettings -> Handle -> r -> Iteratee ByteString IO () outputRowsIter :: CSVeable r => CSVSettings -> Handle -> [r] -> Iteratee ByteString IO () -- | Output given row into given handle outputRow :: CSVeable r => CSVSettings -> Handle -> r -> IO () outputRows :: CSVeable r => CSVSettings -> Handle -> [r] -> IO () -- | Expand or contract the given MapRow to contain exactly the -- given set of columns and then write the row into the given -- Handle. -- -- This is helpful in filtering the columns or perhaps combining a number -- of files that don't have the same columns. -- -- Missing columns will be left empty. outputColumns :: CSVSettings -> Handle -> [ByteString] -> MapRow -> IO () writeHeaders :: CSVeable r => CSVSettings -> Handle -> [r] -> IO () instance CSVeable MapRow instance CSVeable Row