implemented encodeRows

This commit is contained in:
2022-04-24 15:17:52 -04:00
parent 5d6a7db6c5
commit 3df133147f
2 changed files with 26 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ module Data.CSV.Sip (
slurpRawLabelledCSV,
-- * Conduits
-- ** Encoding
encodeRows,
encodeRawRows,
-- ** Decoding
labelFields,
@@ -60,7 +61,7 @@ import Data.Conduit.List (consume)
import qualified Data.Map as M
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8')
import Data.Text.Encoding (decodeUtf8', encodeUtf8)
import Data.Word (Word8)
-- | read an entire CSV file
@@ -97,6 +98,11 @@ slurpRawLabelledCSV
slurpRawLabelledCSV file = runConduit $
sourceFile file .| decodeRawRows .| labelFields .|consume
-- | 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 ()
encodeRows = mapC (map encodeUtf8) .| encodeRawRows
-- | encode raw CSV stream row by row, each element in the list read
-- represents a field, with the entire list representing a row
encodeRawRows :: Monad m => ConduitT [BS.ByteString] BS.ByteString m ()