conduit-extra-1.1.17: Batteries included conduit: adapters for common libraries.

Safe Haskell | None
Language | Haskell98

Data.Conduit.Zlib

Contents

- Conduits
- Flushing
- Decompression combinators
- Re-exported from zlib-bindings

Description

Streaming compression and decompression using conduits.

Parts of this code were taken from zlib-enum and adapted for conduits.

Synopsis

- compress :: (MonadBase base m, PrimMonad base, MonadThrow m) => Int -> WindowBits -> Conduit ByteString m ByteString
- decompress :: (MonadBase base m, PrimMonad base, MonadThrow m) => WindowBits -> Conduit ByteString m ByteString
- gzip :: (MonadThrow m, MonadBase base m, PrimMonad base) => Conduit ByteString m ByteString
- ungzip :: (MonadBase base m, PrimMonad base, MonadThrow m) => Conduit ByteString m ByteString
- compressFlush :: (MonadBase base m, PrimMonad base, MonadThrow m) => Int -> WindowBits -> Conduit (Flush ByteString) m (Flush ByteString)
- decompressFlush :: (MonadBase base m, PrimMonad base, MonadThrow m) => WindowBits -> Conduit (Flush ByteString) m (Flush ByteString)
- multiple :: Monad m => Conduit ByteString m a -> Conduit ByteString m a
- data WindowBits :: * = WindowBits Int
- defaultWindowBits :: WindowBits

# Conduits

compress Source #

Arguments

:: (MonadBase base m, PrimMonad base, 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 (deflate) a stream of `ByteString`s. The `WindowBits` also control the format (zlib vs. gzip).

decompress Source #

Arguments

:: (MonadBase base m, PrimMonad base, MonadThrow m) |
=> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> Conduit ByteString m ByteString |

Decompress (inflate) a stream of `ByteString`s. For example:

       sourceFile "test.z" $= decompress defaultWindowBits $$ sinkFile "test"

gzip :: (MonadThrow m, MonadBase base m, PrimMonad base) => Conduit ByteString m ByteString Source #

Gzip compression with default parameters.

ungzip :: (MonadBase base m, PrimMonad base, MonadThrow m) => Conduit ByteString m ByteString Source #

Gzip decompression with default parameters.

# Flushing

compressFlush Source #

Arguments

:: (MonadBase base m, PrimMonad base, 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) |

Same as `compress`, but allows you to explicitly flush the stream.

decompressFlush Source #

Arguments

:: (MonadBase base m, PrimMonad base, MonadThrow m) |
=> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> Conduit (Flush ByteString) m (Flush ByteString) |

Same as `decompress`, but allows you to explicitly flush the stream.

# Decompression combinators

multiple :: Monad m => Conduit ByteString m a -> Conduit ByteString m a Source #

The standard `decompress` and `ungzip` functions will only decompress a single compressed entity from the stream. This combinator will exhaust the stream completely of all individual compressed entities. This is useful for cases where you have a concatenated archive, e.g. `cat file1.gz file2.gz > combined.gz`.

Usage:

    sourceFile "combined.gz" $$ multiple ungzip =$ consume

This combinator will not fail on an empty stream. If you want to ensure that at least one compressed entity in the stream exists, consider a usage such as:

    sourceFile "combined.gz" $$ (ungzip >> multiple ungzip) =$ consume

Since: 1.1.10

# Re-exported from zlib-bindings

data WindowBits :: * #

Constructors

WindowBits Int |

Instances

Eq WindowBits |
Methods (==) :: WindowBits -> WindowBits -> Bool # (/=) :: WindowBits -> WindowBits -> Bool #
Ord WindowBits |
Methods compare :: WindowBits -> WindowBits -> Ordering # (<) :: WindowBits -> WindowBits -> Bool # (<=) :: WindowBits -> WindowBits -> Bool # (>) :: WindowBits -> WindowBits -> Bool # (>=) :: WindowBits -> WindowBits -> Bool # max :: WindowBits -> WindowBits -> WindowBits # min :: WindowBits -> WindowBits -> WindowBits #
Show WindowBits |
Methods showsPrec :: Int -> WindowBits -> ShowS # show :: WindowBits -> String # showList :: [WindowBits] -> ShowS #
Generic WindowBits |
Associated Types type Rep WindowBits :: * -> * # Methods from :: WindowBits -> Rep WindowBits x # to :: Rep WindowBits x -> WindowBits #
type Rep WindowBits |
type Rep WindowBits = D1 (MetaData "WindowBits" "Codec.Compression.Zlib.Stream" "zlib-0.6.1.2-7negTfm2ujt1gW4wr40MUp" False) ((:+:) (C1 (MetaCons "WindowBits" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))) (C1 (MetaCons "DefaultWindowBits" PrefixI False) U1))

defaultWindowBits :: WindowBits #