Commit 3a8179c1 authored by Mike Ledger's avatar Mike Ledger

support decoding from stdin

parent 40385276
......@@ -193,16 +193,23 @@ decode opts = Csv.decode (if hasHeader' then HasHeader else NoHeader)
Just _ -> True
Nothing -> False
decodeFile :: MonadResource m
=> Options k a
-> FilePath
-> Stream (Of (Either String [ByteString])) m ()
decodeFile
:: MonadResource m
=> Options k a
-> FilePath
-> Stream (Of (Either String [ByteString])) m ()
decodeFile opts fp =
if ".csv" `isSuffixOf` fp
then decode opts (B.readFile fp)
if isCsv
then decode opts inputStream
else S.mapped
(fmap (S.mapOf (Right . (:[]))) . B.toStrict)
(Q.lines (B.readFile fp))
(Q.lines inputStream)
where
isCsv = ".csv" `isSuffixOf` fp || fp == "-"
inputStream =
if fp == "-"
then B.stdin
else B.readFile fp
-- | select the sink to use for output
output :: MonadResource m => Options k a -> B.ByteString m r -> m r
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment