-- 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: -- -- -- -- This library is an attempt to close these gaps. Please note that this -- library started its life based on the enumerator package and has -- recently been ported to work with conduits instead. In the process, it -- has been greatly simplified thanks to the modular nature of the -- conduits library. -- -- Following the port to conduits, the library has also gained the -- ability to parameterize on the stream type and work both with -- ByteString and Text. -- -- For more documentation and examples, check out the README at: -- -- http://github.com/ozataman/csv-conduit @package csv-conduit @version 0.2 -- | This module exports the underlying Attoparsec row parser. This is -- helpful if you want to do some ad-hoc CSV string parsing. module Data.CSV.Conduit.Parser.Text -- | Try to parse given string as CSV parseCSV :: CSVSettings -> Text -> Either String [Row Text] -- | Try to parse given string as 'Row Text' parseRow :: CSVSettings -> Text -> Either String (Maybe (Row Text)) -- | Parse a CSV row row :: CSVSettings -> Parser (Maybe (Row Text)) -- | Parse CSV csv :: CSVSettings -> Parser [Row Text] -- | This module exports the underlying Attoparsec row parser. This is -- helpful if you want to do some ad-hoc CSV string parsing. module Data.CSV.Conduit.Parser.ByteString -- | Try to parse given string as CSV parseCSV :: CSVSettings -> ByteString -> Either String [Row ByteString] -- | Try to parse given string as 'Row ByteString' parseRow :: CSVSettings -> ByteString -> Either String (Maybe (Row ByteString)) -- | Parse a CSV row row :: CSVSettings -> Parser (Maybe (Row ByteString)) -- | Parse CSV csv :: CSVSettings -> Parser [Row ByteString] module Data.CSV.Conduit -- | Represents types r that are CSV-like and can be converted -- to/from an underlying stream of type s. -- -- Example #1: Basics Using Convenience API -- --
--    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)