Compare commits

...

2 Commits

Author SHA1 Message Date
Jonathan Lamothe 886f991ee3 implemented file producers/consumers
- readFromCSV
- readFromCSVRaw
- writeToCSV
- writeToCSVRaw
2022-04-24 18:32:30 -04:00
Jonathan Lamothe 659b817252 removed writeCSVFromStream and writeRawCSVFromStream 2022-04-24 17:15:27 -04:00

View File

@ -35,15 +35,20 @@ module Data.CSV.Sip (
-- ** Write an entire CSV file
writeCSV,
writeRawCSV,
writeCSVFromStream,
writeRawCSVFromStream,
-- * Conduits
-- ** Encoding
-- ** Producers
readFromCSV,
readFromCSVRaw,
encodeCSV,
encodeRawCSV,
-- ** Consumers
writeToCSV,
writeToCSVRaw,
-- ** Transformers
-- *** Encoding
encodeRows,
encodeRawRows,
-- ** Decoding
-- *** Decoding
labelFields,
decodeRows,
decodeRawRows,
@ -127,27 +132,21 @@ writeRawCSV
-> m ()
writeRawCSV file csv = runConduit $ encodeRawCSV csv .| sinkFile file
-- | Write a CSV file from a stream of Text-based rows
writeCSVFromStream
-- | reads a stream of Text-based rows from a CSV file
readFromCSV
:: MonadResource m
=> FilePath
-- ^ the path to the file to write to
-> ConduitT () [T.Text] m ()
-- ^ the source conduit
-> m ()
writeCSVFromStream file src = runConduit $
src .| encodeRows .| sinkFile file
-- ^ the path to the CSV file to read from
-> ConduitT i [T.Text] m ()
readFromCSV file = sourceFile file .| decodeRows
-- | Write a CSV file from a stream of ByteString-based rows
writeRawCSVFromStream
-- | reads a stream of ByteString-based rows from a CSV file
readFromCSVRaw
:: MonadResource m
=> FilePath
-- ^ the path to the file to write to
-> ConduitT () [BS.ByteString] m ()
-- ^ the source conduit
-> m ()
writeRawCSVFromStream file src = runConduit $
src .| encodeRawRows .| sinkFile file
-- ^ 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
@ -165,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 ()