pipes-zlib 0.1.0 → 0.2.0.0
raw patch · 6 files changed
+145/−85 lines, 6 filesdep +pipesdep +zlibdep −pipes-coredep ~basedep ~bytestringnew-uploaderPVP ok
version bump matches the API change (PVP)
Dependencies added: pipes, zlib
Dependencies removed: pipes-core
Dependency ranges changed: base, bytestring
API changes (from Hackage documentation)
- Control.Pipe.Zlib: compress :: MonadIO m => Int -> WindowBits -> Pipe ByteString ByteString m r
- Control.Pipe.Zlib: decompress :: MonadIO m => WindowBits -> Pipe ByteString ByteString m r
- Control.Pipe.Zlib: gunzip :: MonadIO m => Pipe ByteString ByteString m r
- Control.Pipe.Zlib: gzip :: MonadIO m => Pipe ByteString ByteString m r
+ Control.Proxy.Zlib: bestCompression :: CompressionLevel
+ Control.Proxy.Zlib: bestSpeed :: CompressionLevel
+ Control.Proxy.Zlib: compressD :: Proxy p => CompressionLevel -> WindowBits -> () -> Pipe p ByteString ByteString IO r
+ Control.Proxy.Zlib: compressionLevel :: Int -> CompressionLevel
+ Control.Proxy.Zlib: decompressD :: Proxy p => WindowBits -> () -> Pipe p ByteString ByteString IO r
+ Control.Proxy.Zlib: defaultCompression :: CompressionLevel
+ Control.Proxy.Zlib: defaultWindowBits :: WindowBits
+ Control.Proxy.Zlib: noCompression :: CompressionLevel
+ Control.Proxy.Zlib: windowBits :: Int -> WindowBits
Files
- Control/Pipe/Zlib.hs +0/−59
- LICENSE +2/−1
- PEOPLE +6/−0
- README.md +12/−0
- pipes-zlib.cabal +30/−25
- src/Control/Proxy/Zlib.hs +95/−0
− Control/Pipe/Zlib.hs
@@ -1,59 +0,0 @@-module Control.Pipe.Zlib (- gzip,- gunzip,- decompress,- compress- ) where--import Codec.Zlib-import Control.Monad-import Control.Monad.IO.Class-import Control.Pipe-import Control.Pipe.Combinators-import qualified Data.ByteString as B-import Prelude hiding (catch)---- | Gzip compression with default parameters.-gzip :: MonadIO m => Pipe B.ByteString B.ByteString m r-gzip = compress 1 (WindowBits 31)---- | Gzip decompression with default parameters.-gunzip :: MonadIO m => Pipe B.ByteString B.ByteString m r-gunzip = decompress (WindowBits 31)--decompress- :: MonadIO m- => WindowBits- -> Pipe B.ByteString B.ByteString m r-decompress config = do- inf <- liftIO $ initInflate config- let finalize = do chunk <- liftIO $ finishInflate inf- unless (B.null chunk) $ yield chunk- forP' finalize $ \x -> do- popper <- liftIO $ feedInflate inf x- yieldPopper popper--compress- :: MonadIO m- => Int- -> WindowBits- -> Pipe B.ByteString B.ByteString m r-compress level config = do- def <- liftIO $ initDeflate level config- let finalize = yieldPopper (finishDeflate def)- forP' finalize $ \x -> do- popper <- liftIO $ feedDeflate def x- yieldPopper popper--forP' :: Monad m- => Pipe a b m r2- -> (a -> Pipe a b m r1)- -> Pipe a b m r-forP' p f = forP f >> p >> discard--yieldPopper :: MonadIO m => Popper -> Pipe a B.ByteString m ()-yieldPopper pop = do- x <- liftIO pop- case x of- Nothing -> return ()- Just chunk -> yield chunk >> yieldPopper pop
LICENSE view
@@ -1,4 +1,5 @@-Copyright (c) 2012 Paolo Capriotti <p.capriotti@gmail.com>,+Copyright (c) 2012 Paolo Capriotti <p.capriotti@gmail.com>+Copyright (c) 2013 Renzo Carbonara <renzocarbonaraλgmail.com> All rights reserved.
+ PEOPLE view
@@ -0,0 +1,6 @@+The following people have participated in creating this library, either+by directly contributing code or by providing thoughtful input in+discussions about the library design.++Renzo Carbonara+Paolo Capriotti
+ README.md view
@@ -0,0 +1,12 @@+# pipes-zlib++Utilities to deal with zlib compressed streams the **pipes** and libraries.++Check the source or rendered Haddocks for extensive documentation.++This code is licensed under the terms of the so called **3-clause BSD+license**. Read the file named ``LICENSE`` found in this same directory+for details.++See the ``PEOPLE`` file to learn about the people involved in this+effort.
pipes-zlib.cabal view
@@ -1,27 +1,32 @@-Name: pipes-zlib-Version: 0.1.0-License: BSD3-License-file: LICENSE-Author: Paolo Capriotti-Maintainer: p.capriotti@gmail.com-Stability: Experimental-Homepage: https://github.com/pcapriotti/pipes-extra-Category: Control, Enumerator, Compression-Build-type: Simple-Synopsis: Pipes to deal with zipped data.-Description: Pipes to deal with zipped data.-Cabal-version: >=1.8+name: pipes-zlib+version: 0.2.0.0+license: BSD3+license-file: LICENSE+Copyright: Copyright (c) Paolo Capriotti 2012,+ Renzo Carbonara 2013+author: Renzo Carbonara, Paolo Capriotti+maintainer: renzocarbonaraλgmail.com+stability: Experimental+homepage: https://github.com/k0001/pipes-zlib+bug-reports: https://github.com/k0001/pipes-zlib/issues+category: Pipes, Compression+build-type: Simple+synopsis: Pipes to deal with zlib compressed data.+description: Pipes to deal with zlib compressed data.+cabal-version: >=1.8+extra-source-files: README.md PEOPLE -Source-Repository head- Type: git- Location: https://github.com/pcapriotti/pipes-extra+source-repository head+ type: git+ location: git://github.com/k0001/pipes-zlib.git -Library- Build-Depends:- base (== 4.*),- transformers (>= 0.2 && < 0.4),- pipes-core (== 0.1.*),- bytestring (== 0.9.*),- zlib-bindings (== 0.1.*)- Exposed-Modules:- Control.Pipe.Zlib+library+ hs-source-dirs: src+ exposed-modules: Control.Proxy.Zlib+ build-depends: base (>= 4.5 && < 5.0)+ , transformers (>= 0.2 && < 0.4)+ , pipes (>= 3.3 && < 3.4)+ , bytestring (>= 0.9.2.1)+ , zlib (>= 0.5 && < 0.7)+ , zlib-bindings (>= 0.1 && < 0.2)+ ghc-options: -Wall
+ src/Control/Proxy/Zlib.hs view
@@ -0,0 +1,95 @@+-- | This module exports utilities to compress and decompress @pipes@ streams+-- using the zlib compression codec.++module Control.Proxy.Zlib (+ -- * Streams+ decompressD+ , compressD++ -- * Compression level+ -- $ccz-re-export+ , ZC.defaultCompression+ , ZC.noCompression+ , ZC.bestSpeed+ , ZC.bestCompression+ , ZC.compressionLevel++ -- * Window size+ -- $ccz-re-export+ , ZC.defaultWindowBits+ , ZC.windowBits+ ) where++import qualified Codec.Zlib as Z+import qualified Codec.Compression.Zlib as ZC+import Control.Monad (forever, unless)+import Control.Monad.Trans.Class (lift)+import Control.Proxy ((>->))+import qualified Control.Proxy as P+import qualified Data.ByteString as B+import Data.Traversable (mapM)+import Prelude hiding (mapM)++--------------------------------------------------------------------------------++-- | Decompress bytes flowing downstream using the given 'Z.WindowBits'.+--+-- See the "Codec.Zlib" module for details about this values.+decompressD+ :: P.Proxy p+ => Z.WindowBits+ -> () -> P.Pipe p B.ByteString B.ByteString IO r+decompressD config () = P.runIdentityP . forever $ do+ inf <- lift (Z.initInflate config)+ popper <- lift . Z.feedInflate inf =<< P.request ()+ (P.unitD >-> fromPopperS popper) ()+ bs <- lift (Z.finishInflate inf)+ unless (B.null bs) $ P.respond bs++-- | Compress bytes flowing downstream.+--+-- See the "Codec.Zlib" module for details about these values.+compressD+ :: P.Proxy p+ => ZC.CompressionLevel+ -> Z.WindowBits+ -> () -> P.Pipe p B.ByteString B.ByteString IO r+compressD level config () = P.runIdentityP loop where+ loop = forever $ do+ def <- lift (Z.initDeflate level' config)+ popper <- lift . Z.feedDeflate def =<< P.request ()+ (P.unitD >-> fromPopperS popper) ()+ mapM P.respond =<< lift (Z.finishDeflate def)+ level' = fromCompressionLevel level++--------------------------------------------------------------------------------++-- $ccz-re-export+--+-- The following are re-exported from "Codec.Compression.Zlib" for your+-- convenience.++--------------------------------------------------------------------------------+-- Internal stuff++-- | Produce values from the given 'Z.Poppler' until exhausted.+fromPopperS :: P.Proxy p => Z.Popper -> () -> P.Producer p B.ByteString IO ()+fromPopperS pop () = P.runIdentityP loop where+ loop = do+ mbs <- lift pop+ case mbs of+ Nothing -> return ()+ Just bs -> P.respond bs >> loop++-- We need this function until the @zlib@ library hides the+-- 'ZC.CompressionLevel' constructors in future version 0.7.+fromCompressionLevel :: ZC.CompressionLevel -> Int+fromCompressionLevel level = case level of+ ZC.DefaultCompression -> -1+ ZC.NoCompression -> 0+ ZC.BestSpeed -> 1+ ZC.BestCompression -> 9+ ZC.CompressionLevel n+ | n >= 0 && n <= 9 -> fromIntegral n+ _ -> error "CompressLevel must be in the range 1..9"+