implemented file writing
This commit is contained in:
parent
5c74085ada
commit
d27eb91952
|
@ -26,11 +26,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
|
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
|
||||||
|
|
||||||
module Data.CSV.Sip (
|
module Data.CSV.Sip (
|
||||||
-- * Read an entire CSV file
|
-- * Working with Files
|
||||||
|
-- ** Read an entire CSV file
|
||||||
slurpCSV,
|
slurpCSV,
|
||||||
slurpRawCSV,
|
slurpRawCSV,
|
||||||
slurpLabelledCSV,
|
slurpLabelledCSV,
|
||||||
slurpRawLabelledCSV,
|
slurpRawLabelledCSV,
|
||||||
|
-- ** Write an entire CSV file
|
||||||
|
writeCSV,
|
||||||
|
writeRawCSV,
|
||||||
|
writeCSVFromStream,
|
||||||
|
writeRawCSVFromStream,
|
||||||
-- * Conduits
|
-- * Conduits
|
||||||
-- ** Encoding
|
-- ** Encoding
|
||||||
encodeCSV,
|
encodeCSV,
|
||||||
|
@ -51,6 +57,7 @@ import Conduit
|
||||||
, await
|
, await
|
||||||
, mapC
|
, mapC
|
||||||
, runConduit
|
, runConduit
|
||||||
|
, sinkFile
|
||||||
, sourceFile
|
, sourceFile
|
||||||
, yield
|
, yield
|
||||||
, (.|)
|
, (.|)
|
||||||
|
@ -100,6 +107,48 @@ slurpRawLabelledCSV
|
||||||
slurpRawLabelledCSV file = runConduit $
|
slurpRawLabelledCSV file = runConduit $
|
||||||
sourceFile file .| decodeRawRows .| labelFields .|consume
|
sourceFile file .| decodeRawRows .| labelFields .|consume
|
||||||
|
|
||||||
|
-- | write a CSV file from Text-based rows
|
||||||
|
writeCSV
|
||||||
|
:: MonadResource m
|
||||||
|
=> FilePath
|
||||||
|
-- ^ the path to the file to write to
|
||||||
|
-> [[T.Text]]
|
||||||
|
-- ^ the fields/rows being written
|
||||||
|
-> m ()
|
||||||
|
writeCSV file csv = runConduit $ encodeCSV csv .| sinkFile file
|
||||||
|
|
||||||
|
-- | write a CSV file from raw ByteString-based rows
|
||||||
|
writeRawCSV
|
||||||
|
:: MonadResource m
|
||||||
|
=> FilePath
|
||||||
|
-- ^ the path to the file to write to
|
||||||
|
-> [[BS.ByteString]]
|
||||||
|
-- ^ the fields/rows being written
|
||||||
|
-> m ()
|
||||||
|
writeRawCSV file csv = runConduit $ encodeRawCSV csv .| sinkFile file
|
||||||
|
|
||||||
|
-- | Write a CSV file from a stream of Text-based rows
|
||||||
|
writeCSVFromStream
|
||||||
|
:: 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
|
||||||
|
|
||||||
|
-- | Write a CSV file from a stream of ByteString-based rows
|
||||||
|
writeRawCSVFromStream
|
||||||
|
:: 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
|
||||||
|
|
||||||
-- | encode an entire CSV file
|
-- | encode an entire CSV file
|
||||||
encodeCSV
|
encodeCSV
|
||||||
:: Monad m
|
:: Monad m
|
||||||
|
|
Loading…
Reference in New Issue
Block a user