implemented file producers/consumers

- readFromCSV
- readFromCSVRaw
- writeToCSV
- writeToCSVRaw
This commit is contained in:
Jonathan Lamothe 2022-04-24 18:32:30 -04:00
parent 659b817252
commit 886f991ee3

View File

@ -36,12 +36,19 @@ module Data.CSV.Sip (
writeCSV,
writeRawCSV,
-- * Conduits
-- ** Encoding
-- ** Producers
readFromCSV,
readFromCSVRaw,
encodeCSV,
encodeRawCSV,
-- ** Consumers
writeToCSV,
writeToCSVRaw,
-- ** Transformers
-- *** Encoding
encodeRows,
encodeRawRows,
-- ** Decoding
-- *** Decoding
labelFields,
decodeRows,
decodeRawRows,
@ -125,6 +132,22 @@ writeRawCSV
-> m ()
writeRawCSV file csv = runConduit $ encodeRawCSV csv .| sinkFile file
-- | reads a stream of Text-based rows from a CSV file
readFromCSV
:: MonadResource m
=> FilePath
-- ^ the path to the CSV file to read from
-> ConduitT i [T.Text] m ()
readFromCSV file = sourceFile file .| decodeRows
-- | reads a stream of ByteString-based rows from a CSV file
readFromCSVRaw
:: MonadResource m
=> FilePath
-- ^ the path to the CSV file to read from
-> ConduitT i [BS.ByteString] m ()
readFromCSVRaw file = sourceFile file .| decodeRawRows
-- | encode an entire CSV file
encodeCSV
:: Monad m
@ -141,6 +164,22 @@ encodeRawCSV
-> ConduitT () BS.ByteString m ()
encodeRawCSV csv = sourceList csv .| encodeRawRows
-- | Writes a stream of Text-based rows to a CSV file
writeToCSV
:: MonadResource m
=> FilePath
-- ^ the path to the CSV file to write to
-> ConduitT [T.Text] o m ()
writeToCSV file = encodeRows .| sinkFile file
-- | Writes a stream of ByteString-based rows to a CSV file
writeToCSVRaw
:: MonadResource m
=> FilePath
-- ^ the path to the CSV file to write to
-> ConduitT [BS.ByteString] o m ()
writeToCSVRaw file = encodeRawRows .| sinkFile file
-- | encode a CSV stream row by row, each element in the list read
-- represents a field, with the entire list representing a row
encodeRows :: Monad m => ConduitT [T.Text] BS.ByteString m ()