-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A flexible, fast, conduit-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: -- --
-- import Data.Conduit -- import Data.Conduit.Binary -- import Data.Conduit.List as CL -- import Data.CSV.Conduit -- -- myProcessor :: Conduit (Row Text) m (Row Text) -- myProcessor = CL.map reverse -- -- test = runResourceT $ -- transformCSV defCSVSettings -- (sourceFile input.csv) -- myProcessor -- (sinkFile output.csv) ---- -- Example #2: Basics Using Conduit API -- --
-- import Data.Conduit -- import Data.Conduit.Binary -- import Data.CSV.Conduit -- -- myProcessor :: Conduit (Row Text) m (Row Text) -- myProcessor = undefined -- -- test = runResourceT $ -- sourceFile test/BigFile.csv $= -- intoCSV defCSVSettings $= -- myProcessor $= -- fromCSV defCSVSettings $$ -- sinkFile test/BigFileOut.csv --class CSV s r rowToStr :: CSV s r => CSVSettings -> r -> s intoCSV :: (CSV s r, MonadResource m) => CSVSettings -> Conduit s m r fromCSV :: (CSV s r, MonadResource m) => CSVSettings -> Conduit r m s -- | Settings for a CSV file. This library is intended to be flexible and -- offer a way to process the majority of text data files out there. data CSVSettings CSVS :: !Char -> !Maybe Char -> !Maybe Char -> !Char -> CSVSettings -- | Separator character to be used in between fields csvSep :: CSVSettings -> !Char -- | Quote character that may sometimes be present around fields. If -- Nothing is given, the library will never expect quotation even -- if it is present. csvQuoteChar :: CSVSettings -> !Maybe Char -- | Quote character that should be used in the output. csvOutputQuoteChar :: CSVSettings -> !Maybe Char -- | Field separator that should be used in the output. csvOutputColSep :: CSVSettings -> !Char -- | Default settings for a CSV file. -- --
-- csvSep = ',' -- csvQuoteChar = Just '"' -- csvOutputQuoteChar = Just '"' -- csvOutputColSep = ',' --defCSVSettings :: CSVSettings -- | A MapRow is a dictionary based on Map type MapRow a = Map a a -- | A Row is just a list of fields type Row a = [a] -- | Read the entire contents of a CSV file into memory. -- -- An easy way to run this function would be runResourceT after -- feeding it all the arguments. readCSVFile :: (MonadResource m, CSV ByteString a) => CSVSettings -> FilePath -> m [a] -- | General purpose CSV transformer. Apply a list-like processing function -- from List to the rows of a CSV stream. You need to provide a -- stream data source, a transformer and a stream data sink. -- -- An easy way to run this function would be runResourceT after -- feeding it all the arguments. -- -- Example - map a function over the rows of a CSV file: -- --
-- transformCSV set (sourceFile inFile) (C.map f) (sinkFile outFile) --transformCSV :: (MonadResource m, CSV s a, CSV s' b) => CSVSettings -> Source m s -> Conduit a m b -> Sink s' m () -> m () -- | Map over the rows of a CSV file. Provided for convenience for -- historical reasons. -- -- An easy way to run this function would be runResourceT after -- feeding it all the arguments. mapCSVFile :: (MonadResource m, CSV ByteString a, CSV ByteString b) => CSVSettings -> (a -> [b]) -> FilePath -> FilePath -> m () -- | Unwrap a ResourceT transformer, and call all registered release -- actions. -- -- Note that there is some reference counting involved due to -- resourceForkIO. If multiple threads are sharing the same -- collection of resources, only the last call to runResourceT -- will deallocate the resources. -- -- Since 0.3.0 runResourceT :: MonadBaseControl IO m => ResourceT m a -> m a instance (CSV s (Row s'), Ord s', IsString s) => CSV s (MapRow s') instance CSV ByteString (Row Text) instance CSV Text (Row Text) instance CSV ByteString (Row ByteString)