packages feed

pipes-zlib (empty) → 0.0.1

raw patch · 4 files changed

+122/−0 lines, 4 filesdep +basedep +bytestringdep +mtlsetup-changed

Dependencies added: base, bytestring, mtl, pipes-core, zlib-bindings

Files

+ Control/Pipe/Zlib.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Control.Pipe.Zlib (+  gzip,+  gunzip,+  decompress,+  compress+  ) where++-- adapted from conduit++import Codec.Zlib+import Control.Exception (SomeException)+import Control.Monad+import Control.Monad.Trans (MonadIO, liftIO, lift)+import Control.Pipe+import Control.Pipe.Combinators+import Control.Pipe.Exception+import qualified Data.ByteString as B+import Prelude hiding (catch)++-- | Gzip compression with default parameters.+gzip :: MonadIO m => Pipe B.ByteString B.ByteString m ()+gzip = compress 1 (WindowBits 31)++-- | Gzip decompression with default parameters.+gunzip :: MonadIO m => Pipe B.ByteString B.ByteString m ()+gunzip = decompress (WindowBits 31)++decompress+    :: MonadIO m+    => WindowBits+    -> Pipe B.ByteString B.ByteString m ()+decompress config = do+    inf <- lift . liftIO $ initInflate config+    forP $ \x -> do+      chunks <- lift . liftIO $ withInflateInput inf x callback+      mapM_ yield chunks++    chunk <- lift . liftIO $ finishInflate inf+    unless (B.null chunk) $+      yield chunk++compress+    :: MonadIO m+    => Int+    -> WindowBits+    -> Pipe B.ByteString B.ByteString m ()+compress level config = do+    def <- lift . liftIO $ initDeflate level config+    forP $ \x -> do+      chunks <- lift . liftIO $ withDeflateInput def x callback+      mapM_ yield chunks+    chunks <- lift . liftIO $ finishDeflate def callback+    mapM_ yield chunks++callback :: (Show a, MonadIO m) => m (Maybe a) -> m [a]+callback pop = go id where+  go xs = do+    x <- pop+    case x of+      Nothing -> return $ xs []+      Just y -> go (xs . (y:))
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012 Paolo Capriotti <p.capriotti@gmail.com>,++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of  nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pipes-zlib.cabal view
@@ -0,0 +1,27 @@+Name: pipes-zlib+Version: 0.0.1+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++Source-Repository head+    Type: git+    Location: https://github.com/pcapriotti/pipes-extra++Library+    Build-Depends:+        base (== 4.*),+        mtl,+        pipes-core (== 0.0.*),+        bytestring (== 0.9.*),+        zlib-bindings+    Exposed-Modules:+        Control.Pipe.Zlib