conduit-algorithms 0.0.12.0 → 0.0.13.0
raw patch · 4 files changed
+33/−6 lines, 4 files
Files
- ChangeLog +4/−0
- Data/Conduit/Algorithms/Async.hs +18/−4
- conduit-algorithms.cabal +2/−2
- tests/Tests.hs +9/−0
ChangeLog view
@@ -1,3 +1,7 @@+Version 0.0.13.0 2022-08-01 by luispedro+ * Support non-default values for compression level in more compression+ formats+ Version 0.0.12.0 2022-03-20 by luispedro * Add dispatchC_ conduit * Switch to fingertree package (for GHC 9)
Data/Conduit/Algorithms/Async.hs view
@@ -1,6 +1,6 @@ {-| Module : Data.Conduit.Algorithms.Async-Copyright : 2013-2021 Luis Pedro Coelho+Copyright : 2013-2022 Luis Pedro Coelho License : MIT Maintainer : luis@luispedro.org @@ -16,6 +16,7 @@ , asyncMapC , asyncMapEitherC , asyncGzipTo+ , asyncGzipTo' , asyncGzipToFile , asyncGzipFrom , asyncGzipFromFile@@ -24,6 +25,7 @@ , asyncBzip2From , asyncBzip2FromFile , asyncXzTo+ , asyncXzTo' , asyncXzToFile , asyncXzFrom , asyncXzFromFile@@ -229,9 +231,14 @@ -- -- See also 'asyncGzipToFile' asyncGzipTo :: forall m. (MonadIO m, MonadUnliftIO m) => Handle -> C.ConduitT B.ByteString C.Void m ()-asyncGzipTo h = genericAsyncTo gz h+asyncGzipTo = asyncGzipTo' (-1)++-- | A simple sink which performs gzip compression in a separate thread and+-- writes the results to `h` with a given compression level.+asyncGzipTo' :: forall m. (MonadIO m, MonadUnliftIO m) => Int -> Handle -> C.ConduitT B.ByteString C.Void m ()+asyncGzipTo' clevel h = genericAsyncTo gz h where- gz = CZ.gzip `C.catchC` handleZLibException+ gz = CZ.compress clevel (CZ.WindowBits 31) `C.catchC` handleZLibException handleZLibException = \(e :: SZ.ZlibException) -> liftIO . ioError $ mkIOError userErrorType ("Error compressing gzip stream: "++displayException e) (Just h) Nothing @@ -306,6 +313,13 @@ asyncXzTo :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m) => Handle -> C.ConduitT B.ByteString C.Void m () asyncXzTo = genericAsyncTo (CX.compress Nothing) +-- | A simple sink which performs lzma/xz compression in a separate thread and+-- writes the results to `h`.+--+-- See also 'asyncXzToFile' and 'asyncXzTo'+asyncXzTo' :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m) => Int -> Handle -> C.ConduitT B.ByteString C.Void m ()+asyncXzTo' clevel = genericAsyncTo (CX.compress (Just clevel))+ -- | Compresses the output and writes to the given file with compression being -- performed in a separate thread. --@@ -412,7 +426,7 @@ 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+ | ".xz" `isSuffixOf` fname = asyncXzTo' 6 | ".bz2" `isSuffixOf` fname = asyncBzip2To | ".zst" `isSuffixOf` fname = asyncZstdTo 3 | ".zstd" `isSuffixOf` fname = asyncZstdTo 3
conduit-algorithms.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: e2659f2fc195dbd840de065369897ff04fd6484a0d867884a7d8ef845f40ba32+-- hash: 92a9214b73c5e10d0b9b949f0ee1ff3be9366c137750238aa91f8b3ce28ba130 name: conduit-algorithms-version: 0.0.12.0+version: 0.0.13.0 synopsis: Conduit-based algorithms description: Algorithms on Conduits, including higher level asynchronous processing and some other utilities. category: Conduit
tests/Tests.hs view
@@ -17,6 +17,7 @@ import qualified Data.Vector.Storable as VS import Data.Conduit ((.|)) import Data.List (sort)+import System.IO (withFile, IOMode(..)) import System.Directory (removeFile) import Control.Exception (catch, ErrorCall) import Control.Monad (forM_, void)@@ -170,6 +171,14 @@ case_asyncGzip :: IO () case_asyncGzip = do C.runConduitRes (CC.yieldMany ["Hello", " ", "World"] .| CAlg.asyncGzipToFile testingFileNameGZ)+ r <- B.concat <$> extractIO (CAlg.asyncGzipFromFile testingFileNameGZ)+ r @?= "Hello World"+ removeFile testingFileNameGZ++case_asyncGzip_with_non_default_params :: IO ()+case_asyncGzip_with_non_default_params = do+ withFile testingFileNameGZ WriteMode $ \h -> do+ C.runConduitRes (CC.yieldMany ["Hello", " ", "World"] .| CAlg.asyncGzipTo' 1 h) r <- B.concat <$> extractIO (CAlg.asyncGzipFromFile testingFileNameGZ) r @?= "Hello World" removeFile testingFileNameGZ