pipes-zlib-0.4.0/ 0000755 0000000 0000000 00000000000 12274266602 011766 5 ustar 00 0000000 0000000 pipes-zlib-0.4.0/Setup.hs 0000644 0000000 0000000 00000000056 12274266602 013423 0 ustar 00 0000000 0000000 import Distribution.Simple
main = defaultMain
pipes-zlib-0.4.0/README.md 0000644 0000000 0000000 00000000606 12274266602 013247 0 ustar 00 0000000 0000000 # 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-0.4.0/LICENSE 0000644 0000000 0000000 00000003104 12274266602 012771 0 ustar 00 0000000 0000000 Copyright (c) 2012 Paolo Capriotti
Copyright (c) 2013-2014 Renzo Carbonara
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.
pipes-zlib-0.4.0/PEOPLE 0000644 0000000 0000000 00000000361 12274266602 012675 0 ustar 00 0000000 0000000 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
Oliver Charles
Gabriel Gonzalez
pipes-zlib-0.4.0/changelog 0000644 0000000 0000000 00000001037 12274266602 013641 0 ustar 00 0000000 0000000 # Version 0.4.0
* Backwards incompatible API. `compress` and `decompress` are now
functions of `Producer'`s as they need to perform actions at the
beginning and end of input. (Issue #3)
# Version 0.3.1
* Dependency upper bounds.
# Version 0.3.0
* Upgraded to work with pipes-4.0.0, creating a new backwards
incompatible API.
* Generalize base `IO` monad to `MonadIO`.
# Version 0.2.0.0
* New backwards incompatible API.
* Based on pipes-3.3 and zlib-bindings.
# Up to version 0.1.0
* Based on pipes-core and zlib-bindings.
pipes-zlib-0.4.0/pipes-zlib.cabal 0000644 0000000 0000000 00000002374 12274266602 015036 0 ustar 00 0000000 0000000 name: pipes-zlib
version: 0.4.0
license: BSD3
license-file: LICENSE
Copyright: Copyright (c) Paolo Capriotti 2012,
Renzo Carbonara 2013-2014
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: Zlib compression and decompression for Pipes streams
description: Zlib compression and decompression for Pipes streams
cabal-version: >=1.8
extra-source-files: README.md PEOPLE changelog
source-repository head
type: git
location: git://github.com/k0001/pipes-zlib.git
library
hs-source-dirs: src
exposed-modules: Pipes.Zlib
build-depends: base (>= 4.5 && < 5.0)
, transformers (>= 0.2 && < 0.4)
, pipes (>= 4.0 && < 4.2)
, bytestring (>= 0.9.2.1)
, zlib (>= 0.5 && < 0.7)
, zlib-bindings (>= 0.1 && < 0.2)
ghc-options: -Wall -O2
pipes-zlib-0.4.0/src/ 0000755 0000000 0000000 00000000000 12274266602 012555 5 ustar 00 0000000 0000000 pipes-zlib-0.4.0/src/Pipes/ 0000755 0000000 0000000 00000000000 12274266602 013635 5 ustar 00 0000000 0000000 pipes-zlib-0.4.0/src/Pipes/Zlib.hs 0000644 0000000 0000000 00000006034 12274266602 015074 0 ustar 00 0000000 0000000 {-# LANGUAGE RankNTypes #-}
-- | This module exports utilities to compress and decompress @pipes@ streams
-- using the zlib compression codec.
module Pipes.Zlib (
-- * Streams
decompress
, compress
-- * 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.Compression.Zlib as ZC
import qualified Codec.Zlib as Z
import Control.Monad (unless)
import qualified Data.ByteString as B
import Pipes
--------------------------------------------------------------------------------
-- | Decompress bytes flowing from a 'Producer'.
--
-- See the "Codec.Compression.Zlib" module for details about 'Z.WindowBits'.
decompress
:: MonadIO m
=> ZC.WindowBits
-> Producer' B.ByteString m r -- ^ Compressed stream
-> Producer' B.ByteString m r -- ^ Decompressed stream
decompress wbits p0 = do
inf <- liftIO $ Z.initInflate wbits
r <- for p0 $ \bs -> do
popper <- liftIO (Z.feedInflate inf bs)
fromPopper popper
bs <- liftIO $ Z.finishInflate inf
unless (B.null bs) (yield bs)
return r
{-# INLINABLE decompress #-}
-- | Compress bytes flowing from a 'Producer'.
--
-- See the "Codec.Compression.Zlib" module for details about
-- 'ZC.CompressionLevel' and 'ZC.WindowBits'.
compress
:: MonadIO m
=> ZC.CompressionLevel
-> ZC.WindowBits
-> Producer' B.ByteString m r -- ^ Decompressed stream
-> Producer' B.ByteString m r -- ^ Compressed stream
compress clevel wbits p0 = do
def <- liftIO $ Z.initDeflate (fromCompressionLevel clevel) wbits
r <- for p0 $ \bs -> do
popper <- liftIO (Z.feedDeflate def bs)
fromPopper popper
mbs <- liftIO $ Z.finishDeflate def
case mbs of
Just bs -> yield bs
Nothing -> return ()
return r
{-# INLINABLE compress #-}
--------------------------------------------------------------------------------
-- $ccz-re-export
--
-- The following are re-exported from "Codec.Compression.Zlib" for your
-- convenience.
--------------------------------------------------------------------------------
-- Internal stuff
-- | Produce values from the given 'Z.Popper' until exhausted.
fromPopper :: MonadIO m => Z.Popper -> Producer' B.ByteString m ()
fromPopper pop = loop where
loop = do
mbs <- liftIO pop
case mbs of
Nothing -> return ()
Just bs -> yield bs >> loop
{-# INLINABLE fromPopper #-}
-- 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"