Data.Conduit.Zlib

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

Safe Haskell | None
Language | Haskell2010

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 :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => Int -> WindowBits -> ConduitT ByteString ByteString m ()
- decompress :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => WindowBits -> ConduitT ByteString ByteString m ()
- gzip :: forall (m :: Type -> Type). (MonadThrow m, PrimMonad m) => ConduitT ByteString ByteString m ()
- ungzip :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => ConduitT ByteString ByteString m ()
- compressFlush :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => Int -> WindowBits -> ConduitT (Flush ByteString) (Flush ByteString) m ()
- decompressFlush :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => WindowBits -> ConduitT (Flush ByteString) (Flush ByteString) m ()
- multiple :: forall (m :: Type -> Type) a. Monad m => ConduitT ByteString a m () -> ConduitT ByteString a m ()
- newtype WindowBits = WindowBits Int
- defaultWindowBits :: WindowBits

# Conduits

compress #

Arguments

:: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) |
=> Int | Compression level
-> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> ConduitT ByteString ByteString m () |

Compress (deflate) a stream of `ByteString`s. The `WindowBits` also control the format (zlib vs. gzip).

decompress #

Arguments

:: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) |
=> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> ConduitT ByteString ByteString m () |

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

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

gzip :: forall (m :: Type -> Type). (MonadThrow m, PrimMonad m) => ConduitT ByteString ByteString m () #

Gzip compression with default parameters.

ungzip :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => ConduitT ByteString ByteString m () #

Gzip decompression with default parameters.

# Flushing

compressFlush #

Arguments

:: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) |
=> Int | Compression level
-> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> ConduitT (Flush ByteString) (Flush ByteString) m () |

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

decompressFlush #

Arguments

:: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) |
=> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> ConduitT (Flush ByteString) (Flush ByteString) m () |

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

# Decompression combinators

multiple :: forall (m :: Type -> Type) a. Monad m => ConduitT ByteString a m () -> ConduitT ByteString a m () #

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

newtype WindowBits #

This specifies the size of the compression window. Larger values of this parameter result in better compression at the expense of higher memory usage.

The compression window size is the value of the the window bits raised to the power 2. The window bits must be in the range `9..15` which corresponds to compression window sizes of 512b to 32Kb. The default is 15 which is also the maximum size.

The total amount of memory used depends on the window bits and the `MemoryLevel`. See the `MemoryLevel` for the details.

Constructors

WindowBits Int |

#### Instances

Instances details

Generic WindowBits |
Instance details Defined in Codec.Compression.Zlib.Stream Associated Types
type Rep WindowBits |
Instance details Defined in Codec.Compression.Zlib.Stream type Rep WindowBits = D1 ('MetaData "WindowBits" "Codec.Compression.Zlib.Stream" "zlib-0.7.1.0-1mOT4jASaJp8whxsM9AySZ" 'True) (C1 ('MetaCons "WindowBits" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
Methods from :: WindowBits -> Rep WindowBits x # to :: Rep WindowBits x -> WindowBits #
Show WindowBits |
Instance details Defined in Codec.Compression.Zlib.Stream Methods showsPrec :: Int -> WindowBits -> ShowS # show :: WindowBits -> String # showList :: [WindowBits] -> ShowS #
Eq WindowBits |
Instance details Defined in Codec.Compression.Zlib.Stream Methods (==) :: WindowBits -> WindowBits -> Bool # (/=) :: WindowBits -> WindowBits -> Bool #
Ord WindowBits |
Instance details Defined in Codec.Compression.Zlib.Stream 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 #
type Rep WindowBits |
Instance details Defined in Codec.Compression.Zlib.Stream type Rep WindowBits = D1 ('MetaData "WindowBits" "Codec.Compression.Zlib.Stream" "zlib-0.7.1.0-1mOT4jASaJp8whxsM9AySZ" 'True) (C1 ('MetaCons "WindowBits" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

defaultWindowBits :: WindowBits #

The default `WindowBits`. Equivalent to ``windowBits` 15`. which is also the maximum size.