conduit-algorithms 0.0.9.0 → 0.0.10.1
raw patch · 4 files changed
+64/−6 lines, 4 files
Files
- ChangeLog +6/−0
- Data/Conduit/Algorithms/Async.hs +37/−1
- conduit-algorithms.cabal +6/−5
- tests/Tests.hs +15/−0
ChangeLog view
@@ -1,3 +1,9 @@+Version 0.0.10.1 2019-05-31 by luispedro+ * Accept .zst as extension for zstandard++Version 0.0.10.0 2019-03-01 by luispedro+ * Add withPossiblyCompressedFileOutput:+ Version 0.0.9.0 2019-01-09 by luispedro * Add Zstandard compression * Refactor internals to avoid code repetition
Data/Conduit/Algorithms/Async.hs view
@@ -12,6 +12,7 @@ ( conduitPossiblyCompressedFile , conduitPossiblyCompressedToFile , withPossiblyCompressedFile+ , withPossiblyCompressedFileOutput , asyncMapC , asyncMapEitherC , asyncGzipTo@@ -367,7 +368,7 @@ -- @ -- -- withPossiblyCompressedFile fname $ \src ->--- src .| mySink+-- runConduit (src .| mySink) -- @ -- -- Unlike 'conduitPossiblyCompressedFile', this ensures that the file is closed@@ -384,10 +385,41 @@ | ".gz" `isSuffixOf` fname = asyncGzipFrom | ".xz" `isSuffixOf` fname = asyncXzFrom | ".bz2" `isSuffixOf` fname = asyncBzip2From+ | ".zst" `isSuffixOf` fname = asyncZstdFrom | ".zstd" `isSuffixOf` fname = asyncZstdFrom | otherwise = C.sourceHandle +-- | If the filename indicates a supported compressed file (gzip, xz, and, on+-- Unix, bzip2), then it provides an output source+--+-- Usage+--+-- @+--+-- withPossiblyCompressedFileOutput fname $ \out ->+-- runConduit (mySrc .| out)+-- @+--+-- This ensures that the file is closed even if the conduit terminates early.+--+-- On Windows, attempting to read from a bzip2 file, results in 'error'.+withPossiblyCompressedFileOutput :: (MonadUnliftIO m, MonadResource m, MonadThrow m) => FilePath -> (C.ConduitT B.ByteString C.Void m () -> m a) -> m a+withPossiblyCompressedFileOutput fname inner = withRunInIO $ \run -> do+ IO.withBinaryFile fname IO.WriteMode $+ run . inner . withPossiblyCompressedFileOutput' fname+++withPossiblyCompressedFileOutput' :: (MonadUnliftIO m, MonadResource m, MonadThrow m) => FilePath -> Handle -> C.ConduitT B.ByteString C.Void m ()+withPossiblyCompressedFileOutput' fname+ | ".gz" `isSuffixOf` fname = asyncGzipTo+ | ".xz" `isSuffixOf` fname = asyncXzTo+ | ".bz2" `isSuffixOf` fname = asyncBzip2To+ | ".zst" `isSuffixOf` fname = asyncZstdTo 3+ | ".zstd" `isSuffixOf` fname = asyncZstdTo 3+ | otherwise = C.sinkHandle++ -- | If the filename indicates a gzipped file (or, on Unix, also a bz2 file), -- then it reads it and uncompresses it. --@@ -401,17 +433,21 @@ | ".gz" `isSuffixOf` fname = asyncGzipFromFile fname | ".xz" `isSuffixOf` fname = asyncXzFromFile fname | ".bz2" `isSuffixOf` fname = asyncBzip2FromFile fname+ | ".zst" `isSuffixOf` fname = asyncZstdFromFile fname | ".zstd" `isSuffixOf` fname = asyncZstdFromFile fname | otherwise = C.sourceFile fname -- | If the filename indicates a gzipped file (or, on Unix, also a bz2 file), -- then it compresses and write with the algorithm matching the filename --+-- Consider using 'withPossiblyCompressedFileOutput' to ensure prompt file closing.+-- -- On Windows, attempting to write to a bzip2 file, results in 'error'. conduitPossiblyCompressedToFile :: (MonadUnliftIO m, MonadResource m) => FilePath -> C.ConduitT B.ByteString C.Void m () conduitPossiblyCompressedToFile fname | ".gz" `isSuffixOf` fname = asyncGzipToFile fname | ".xz" `isSuffixOf` fname = asyncXzToFile fname | ".bz2" `isSuffixOf` fname = asyncBzip2ToFile fname+ | ".zst" `isSuffixOf` fname = asyncZstdToFile fname | ".zstd" `isSuffixOf` fname = asyncZstdToFile fname | otherwise = C.sinkFile fname
conduit-algorithms.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.1. -- -- see: https://github.com/sol/hpack ----- hash: 568a611355a3ef3c59150cc32f207c38a0d6d802487517f30c8e437c8c839ab8+-- hash: 970b58ff0d5b7502e92faea1119a63d4779237c3e4c31595392ce40d3cad6957 name: conduit-algorithms-version: 0.0.9.0+version: 0.0.10.1 synopsis: Conduit-based algorithms description: Algorithms on Conduits, including higher level asynchronous processing and some other utilities. category: Conduit@@ -16,10 +18,9 @@ license: MIT license-file: COPYING build-type: Simple-cabal-version: >= 1.10 extra-source-files:- ChangeLog README.md+ ChangeLog source-repository head type: git
tests/Tests.hs view
@@ -235,6 +235,21 @@ removeFile testingFileNameGZ back @?= testdata +case_withPossiblyCompressedFileOutput :: IO ()+case_withPossiblyCompressedFileOutput = do+ let testdata = [0 :: Int .. 14]+ R.runResourceT $+ CAlg.withPossiblyCompressedFileOutput testingFileNameGZ $ \sink ->+ C.runConduit $+ CC.yieldMany testdata+ .| CL.map (B8.pack . (\n -> show n ++ "\n"))+ .| sink+ back <- R.runResourceT $+ CAlg.withPossiblyCompressedFile testingFileNameGZ $ \src ->+ C.runConduit (src .| CB.lines .| CL.map (read . B8.unpack) .| CC.sinkList)+ removeFile testingFileNameGZ+ back @?= testdata+ case_async_bzip2_to_from :: IO () case_async_bzip2_to_from = do let testdata = [0 :: Int .. 12]