jsonl-conduit 0.1.1 → 0.1.2
raw patch · 3 files changed
+44/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ JSONL.Conduit: sourceFileC_ :: MonadResource m => FilePath -> ConduitT () ByteString m ()
Files
- CHANGELOG.md +3/−0
- jsonl-conduit.cabal +2/−1
- src/JSONL/Conduit.hs +39/−0
+ CHANGELOG.md view
@@ -0,0 +1,3 @@+0.1.2++add sourceFileC_
jsonl-conduit.cabal view
@@ -1,5 +1,5 @@ name: jsonl-conduit-version: 0.1.1+version: 0.1.2 synopsis: Conduit interface to JSONL-encoded data description: Streaming interface to JSONL-encoded files and bytestrings homepage: https://github.com/unfoldml/jsonl@@ -11,6 +11,7 @@ category: JSON, Web, Text build-type: Simple extra-source-files: README.md+ CHANGELOG.md records cabal-version: >=1.10 tested-with: GHC == 9.0.2
src/JSONL/Conduit.hs view
@@ -13,6 +13,7 @@ , jsonFromLBSC -- ** I/O , sourceFileC+ , sourceFileC_ ) where import Data.Void (Void)@@ -94,6 +95,44 @@ Right (y, srest) -> do C.yield y go srest++-- | The outgoing stream elements are the lines of the file, i.e guaranteed not to contain newline characters+--+-- NB : In case it wasn't clear, no JSON parsing is done, only string copies+sourceFileC_ :: MonadResource m =>+ FilePath -- ^ path of JSONL file to be read+ -> C.ConduitT () LBS.ByteString m ()+sourceFileC_ fpath = C.sourceFile fpath .|+ toLazyLines++toLazyLines :: (Monad m) => C.ConduitT BS.ByteString LBS.ByteString m ()+toLazyLines = go mempty+ where+ go acc =+ if not (BS.null acc)+ then+ do+ let+ (y, srest) = chop acc+ C.yield y+ go srest+ else+ do+ mc <- C.await+ case mc of+ Nothing -> pure ()+ Just x -> do+ let+ acc' = acc <> x+ (y, srest) = chop acc'+ C.yield y+ go srest+++chop :: BS.ByteString -> (LBS.ByteString, BS.ByteString)+chop acc = (LBS.fromStrict s, srest)+ where+ (s, srest) = chopBS8 acc chopDecode :: FromJSON a => BS.ByteString -> Either String (a, BS.ByteString)