packages feed

zlib-conduit 1.0.0 → 1.1.0

raw patch · 2 files changed

+3/−182 lines, 2 filesdep −QuickCheckdep −bytestringdep −containersdep ~basedep ~conduit

Dependencies removed: QuickCheck, bytestring, containers, hspec, resourcet, transformers, void, zlib-bindings, zlib-conduit

Dependency ranges changed: base, conduit

Files

− Data/Conduit/Zlib.hs
@@ -1,155 +0,0 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE RankNTypes #-}--- | Streaming compression and decompression using conduits.------ Parts of this code were taken from zlib-enum and adapted for conduits.-module Data.Conduit.Zlib (-    -- * Conduits-    compress, decompress, gzip, ungzip,-    -- * Flushing-    compressFlush, decompressFlush,-    -- * Re-exported from zlib-bindings-    WindowBits (..), defaultWindowBits-) where--import Codec.Zlib-import Data.Conduit hiding (unsafeLiftIO)-import qualified Data.Conduit as C (unsafeLiftIO)-import Data.ByteString (ByteString)-import qualified Data.ByteString as S-import Control.Exception (try)-import Control.Monad ((<=<), unless, liftM)-import Control.Monad.Trans.Class (lift, MonadTrans)---- | Gzip compression with default parameters.-gzip :: (MonadThrow m, MonadUnsafeIO m) => Conduit ByteString m ByteString-gzip = compress 1 (WindowBits 31)---- | Gzip decompression with default parameters.-ungzip :: (MonadUnsafeIO m, MonadThrow m) => Conduit ByteString m ByteString-ungzip = decompress (WindowBits 31)--unsafeLiftIO :: (MonadUnsafeIO m, MonadThrow m) => IO a -> m a-unsafeLiftIO =-    either rethrow return <=< C.unsafeLiftIO . try-  where-    rethrow :: MonadThrow m => ZlibException -> m a-    rethrow = monadThrow---- |--- Decompress (inflate) a stream of 'ByteString's. For example:------ >    sourceFile "test.z" $= decompress defaultWindowBits $$ sinkFile "test"--decompress-    :: (MonadUnsafeIO m, MonadThrow m)-    => WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)-    -> Conduit ByteString m ByteString-decompress =-    helperDecompress (liftM (fmap Chunk) await) yield'-  where-    yield' Flush = return ()-    yield' (Chunk bs) = yield bs---- | Same as 'decompress', but allows you to explicitly flush the stream.-decompressFlush-    :: (MonadUnsafeIO m, MonadThrow m)-    => WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)-    -> Conduit (Flush ByteString) m (Flush ByteString)-decompressFlush = helperDecompress await yield--helperDecompress :: (Monad (t m), MonadUnsafeIO m, MonadThrow m, MonadTrans t)-                 => t m (Maybe (Flush ByteString))-                 -> (Flush ByteString -> t m ())-                 -> WindowBits-                 -> t m ()-helperDecompress await' yield' config =-    await' >>= maybe (return ()) start-  where-    start input = do-        inf <- lift $ unsafeLiftIO $ initInflate config-        push inf input--    continue inf = await' >>= maybe (close inf) (push inf)--    goPopper popper = do-        mbs <- lift $ unsafeLiftIO popper-        case mbs of-            Nothing -> return ()-            Just bs -> yield' (Chunk bs) >> goPopper popper--    push inf (Chunk x) = do-        popper <- lift $ unsafeLiftIO $ feedInflate inf x-        goPopper popper-        continue inf--    push inf Flush = do-        chunk <- lift $ unsafeLiftIO $ flushInflate inf-        unless (S.null chunk) $ yield' $ Chunk chunk-        yield' Flush-        continue inf--    close inf = do-        chunk <- lift $ unsafeLiftIO $ finishInflate inf-        unless (S.null chunk) $ yield' $ Chunk chunk---- |--- Compress (deflate) a stream of 'ByteString's. The 'WindowBits' also control--- the format (zlib vs. gzip).--compress-    :: (MonadUnsafeIO m, MonadThrow m)-    => Int         -- ^ Compression level-    -> WindowBits  -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)-    -> Conduit ByteString m ByteString-compress =-    helperCompress (liftM (fmap Chunk) await) yield'-  where-    yield' Flush = return ()-    yield' (Chunk bs) = yield bs---- | Same as 'compress', but allows you to explicitly flush the stream.-compressFlush-    :: (MonadUnsafeIO m, MonadThrow m)-    => Int         -- ^ Compression level-    -> WindowBits  -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)-    -> Conduit (Flush ByteString) m (Flush ByteString)-compressFlush = helperCompress await yield--helperCompress :: (Monad (t m), MonadUnsafeIO m, MonadThrow m, MonadTrans t)-               => t m (Maybe (Flush ByteString))-               -> (Flush ByteString -> t m ())-               -> Int-               -> WindowBits-               -> t m ()-helperCompress await' yield' level config =-    await' >>= maybe (return ()) start-  where-    start input = do-        def <- lift $ unsafeLiftIO $ initDeflate level config-        push def input--    continue def = await' >>= maybe (close def) (push def)--    goPopper popper = do-        mbs <- lift $ unsafeLiftIO popper-        case mbs of-            Nothing -> return ()-            Just bs -> yield' (Chunk bs) >> goPopper popper--    push def (Chunk x) = do-        popper <- lift $ unsafeLiftIO $ feedDeflate def x-        goPopper popper-        continue def--    push def Flush = do-        mchunk <- lift $ unsafeLiftIO $ flushDeflate def-        maybe (return ()) (yield' . Chunk) mchunk-        yield' Flush-        continue def--    close def = do-        mchunk <- lift $ unsafeLiftIO $ finishDeflate def-        case mchunk of-            Nothing -> return ()-            Just chunk -> yield' (Chunk chunk) >> close def
zlib-conduit.cabal view
@@ -1,6 +1,6 @@ Name:                zlib-conduit-Version:             1.0.0-Synopsis:            Streaming compression/decompression via conduits.+Version:             1.1.0+Synopsis:            Streaming compression/decompression via conduits. (deprecated) Description:         Streaming compression/decompression via conduits. License:             BSD3 License-file:        LICENSE@@ -12,33 +12,9 @@ Homepage:            http://github.com/snoyberg/conduit extra-source-files:  test/main.hs -flag debug- Library-  Exposed-modules:     Data.Conduit.Zlib   Build-depends:       base                     >= 4            && < 5-                     , containers-                     , transformers             >= 0.2.2        && < 0.4-                     , bytestring               >= 0.9-                     , zlib-bindings            >= 0.1          && < 0.2-                     , conduit                  >= 1.0          && < 1.1-                     , void-  ghc-options:     -Wall--test-suite test-    hs-source-dirs: test-    main-is: main.hs-    type: exitcode-stdio-1.0-    cpp-options:   -DTEST-    build-depends:   conduit-                   , base-                   , hspec >= 1.3-                   , QuickCheck-                   , bytestring-                   , transformers-                   , zlib-conduit-                   , resourcet-    ghc-options:     -Wall+                , conduit >= 1.1  source-repository head   type:     git