jsonl-conduit 0.1.0.2 → 0.1.1
raw patch · 3 files changed
+26/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ JSONL.Conduit: appendFileC :: (ToJSON a, MonadResource m) => FilePath -> ConduitT a o m ()
Files
- README.md +3/−0
- jsonl-conduit.cabal +3/−3
- src/JSONL/Conduit.hs +20/−2
README.md view
@@ -1,3 +1,6 @@ # jsonl-conduit Streaming interface to JSONL data based on `conduit`.+++JSON Lines format : https://jsonlines.org/
jsonl-conduit.cabal view
@@ -1,8 +1,8 @@ name: jsonl-conduit-version: 0.1.0.2+version: 0.1.1 synopsis: Conduit interface to JSONL-encoded data description: Streaming interface to JSONL-encoded files and bytestrings-homepage: https://github.com/unfoldml/jsonl-conduit+homepage: https://github.com/unfoldml/jsonl license: BSD3 license-file: LICENSE author: Marco Zocca@@ -44,4 +44,4 @@ source-repository head type: git- location: https://github.com/unfoldml/jsonl-conduit+ location: https://github.com/unfoldml/jsonl
src/JSONL/Conduit.hs view
@@ -1,10 +1,14 @@ {-# LANGUAGE TupleSections #-} {-# options_ghc -Wno-unused-imports #-}+-- | Streaming interface for JSONL-encoded files, based on @conduit@+--+-- The JSONL (JSON Lines) format : https://jsonlines.org/ module JSONL.Conduit ( -- * Encode jsonToLBSC -- ** I/O , sinkFileC+ , appendFileC -- * Decode , jsonFromLBSC -- ** I/O@@ -14,6 +18,7 @@ import Data.Void (Void) import Control.Monad.IO.Class (MonadIO(..))+import System.IO (IOMode(..), Handle, openBinaryFile) -- aeson import Data.Aeson (ToJSON(..), FromJSON(..), eitherDecode' )@@ -24,7 +29,7 @@ import qualified Data.ByteString.Char8 as BS8 (span, drop, putStrLn, putStr) import qualified Data.ByteString.Lazy as LBS (ByteString, drop, span, toStrict, fromStrict) -- conduit-import qualified Conduit as C (ConduitT, runConduit, sourceFile, sinkFile, await, yield, mapC, unfoldC, foldMapC, foldlC, printC)+import qualified Conduit as C (ConduitT, runConduit, sourceFile, sinkFile, await, yield, mapC, unfoldC, foldMapC, foldlC, printC, sinkIOHandle) import Conduit ( (.|) , MonadResource) -- jsonl import JSONL (jsonLine)@@ -41,8 +46,21 @@ sinkFileC :: (ToJSON a, MonadResource m) => FilePath -- ^ path of JSONL file to be created -> C.ConduitT a o m ()-sinkFileC fpath = C.mapC (LBS.toStrict . BBS.toLazyByteString . jsonLine) .|+sinkFileC fpath = C.mapC encodeJSONL .| C.sinkFile fpath++-- | Like `sinkFileC` but in `AppendMode`, which means that the handle is positioned at the+-- end of the file.+--+-- @since 0.1.1+appendFileC :: (ToJSON a, MonadResource m) =>+ FilePath+ -> C.ConduitT a o m ()+appendFileC fpath = C.mapC encodeJSONL .|+ C.sinkIOHandle (openBinaryFile fpath AppendMode)++encodeJSONL :: ToJSON a => a -> BS.ByteString+encodeJSONL = LBS.toStrict . BBS.toLazyByteString . jsonLine -- | Read a JSONL file and stream the decoded records --