Codec.Compression.Zlib

zlib-0.7.1.0: Compression and decompression in the gzip and zlib formats

Copyright | (c) 2006-2014 Duncan Coutts
License | BSD-style
Maintainer | duncan@community.haskell.org
Safe Haskell | Safe-Inferred
Language | Haskell2010

Codec.Compression.Zlib

Contents

- Simple compression and decompression
- Extended API with control over compression parameters
  - The compression parameter types

Description

Compression and decompression of data streams in the zlib format.

The format is described in detail in RFC #1950: http://www.ietf.org/rfc/rfc1950.txt

See also the zlib home page: http://zlib.net/

Synopsis

- compress :: ByteString -> ByteString
- decompress :: ByteString -> ByteString
- data DecompressError
  - = TruncatedInput
  - | DictionaryRequired
  - | DictionaryMismatch
  - | DataFormatError String
- compressWith :: CompressParams -> ByteString -> ByteString
- decompressWith :: DecompressParams -> ByteString -> ByteString
- data CompressParams = CompressParams {
  - compressLevel :: !CompressionLevel
  - compressMethod :: !Method
  - compressWindowBits :: !WindowBits
  - compressMemoryLevel :: !MemoryLevel
  - compressStrategy :: !CompressionStrategy
  - compressBufferSize :: !Int
  - compressDictionary :: Maybe ByteString
  }
- defaultCompressParams :: CompressParams
- data DecompressParams = DecompressParams {
  - decompressWindowBits :: !WindowBits
  - decompressBufferSize :: !Int
  - decompressDictionary :: Maybe ByteString
  - decompressAllMembers :: Bool
  }
- defaultDecompressParams :: DecompressParams
- newtype CompressionLevel = CompressionLevel Int
- defaultCompression :: CompressionLevel
- noCompression :: CompressionLevel
- bestSpeed :: CompressionLevel
- bestCompression :: CompressionLevel
- compressionLevel :: Int -> CompressionLevel
- data Method
- deflateMethod :: Method
- newtype WindowBits = WindowBits Int
- defaultWindowBits :: WindowBits
- windowBits :: Int -> WindowBits
- newtype MemoryLevel = MemoryLevel Int
- defaultMemoryLevel :: MemoryLevel
- minMemoryLevel :: MemoryLevel
- maxMemoryLevel :: MemoryLevel
- memoryLevel :: Int -> MemoryLevel
- data CompressionStrategy
- defaultStrategy :: CompressionStrategy
- filteredStrategy :: CompressionStrategy
- huffmanOnlyStrategy :: CompressionStrategy
- rleStrategy :: CompressionStrategy
- fixedStrategy :: CompressionStrategy

# Documentation

This module provides pure functions for compressing and decompressing streams of data in the zlib format and represented by lazy `ByteString`s. This makes it easy to use either in memory or with disk or network IO.

# Simple compression and decompression

compress :: ByteString -> ByteString #

Compress a stream of data into the zlib format.

This uses the default compression parameters. In particular it uses the default compression level which favours a higher compression ratio over compression speed, though it does not use the maximum compression level.

Use `compressWith` to adjust the compression level or other compression parameters.

decompress :: ByteString -> ByteString #

Decompress a stream of data in the zlib format, throw `DecompressError` on failure.

Note that the decompression is performed lazily. Errors in the data stream may not be detected until the end of the stream is demanded (since it is only at the end that the final checksum can be checked). If this is important to you, you must make sure to consume the whole decompressed stream before doing any IO action that depends on it.

data DecompressError #

The possible error cases when decompressing a stream.

This can be `show`n to give a human readable error message.

Constructors

TruncatedInput | The compressed data stream ended prematurely. This may happen if the input data stream was truncated.
DictionaryRequired | It is possible to do zlib compression with a custom dictionary. This allows slightly higher compression ratios for short files. However such compressed streams require the same dictionary when decompressing. This error is for when we encounter a compressed stream that needs a dictionary, and it's not provided.
DictionaryMismatch | If the stream requires a dictionary and you provide one with the wrong `DictionaryHash` then you will get this error.
DataFormatError String | If the compressed data stream is corrupted in any way then you will get this error, for example if the input data just isn't a compressed zlib data stream. In particular if the data checksum turns out to be wrong then you will get all the decompressed data but this error at the end, instead of the normal successful `StreamEnd`.

#### Instances

Instances details

Exception DecompressError # |
Instance details Defined in Codec.Compression.Zlib.Internal Methods toException :: DecompressError -> SomeException # fromException :: SomeException -> Maybe DecompressError # displayException :: DecompressError -> String #
Generic DecompressError # |
Instance details Defined in Codec.Compression.Zlib.Internal Associated Types
type Rep DecompressError | Since: zlib-0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal type Rep DecompressError = D1 ('MetaData "DecompressError" "Codec.Compression.Zlib.Internal" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) ((C1 ('MetaCons "TruncatedInput" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DictionaryRequired" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "DictionaryMismatch" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DataFormatError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))
Methods from :: DecompressError -> Rep DecompressError x # to :: Rep DecompressError x -> DecompressError #
Show DecompressError # |
Instance details Defined in Codec.Compression.Zlib.Internal Methods showsPrec :: Int -> DecompressError -> ShowS # show :: DecompressError -> String # showList :: [DecompressError] -> ShowS #
Eq DecompressError # |
Instance details Defined in Codec.Compression.Zlib.Internal Methods (==) :: DecompressError -> DecompressError -> Bool # (/=) :: DecompressError -> DecompressError -> Bool #
Ord DecompressError # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal Methods compare :: DecompressError -> DecompressError -> Ordering # (<) :: DecompressError -> DecompressError -> Bool # (<=) :: DecompressError -> DecompressError -> Bool # (>) :: DecompressError -> DecompressError -> Bool # (>=) :: DecompressError -> DecompressError -> Bool # max :: DecompressError -> DecompressError -> DecompressError # min :: DecompressError -> DecompressError -> DecompressError #
type Rep DecompressError # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal type Rep DecompressError = D1 ('MetaData "DecompressError" "Codec.Compression.Zlib.Internal" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) ((C1 ('MetaCons "TruncatedInput" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DictionaryRequired" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "DictionaryMismatch" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DataFormatError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))

# Extended API with control over compression parameters

compressWith :: CompressParams -> ByteString -> ByteString #

Like `compress` but with the ability to specify various compression parameters. Typical usage:

    compressWith defaultCompressParams { ... }

In particular you can set the compression level:

    compressWith defaultCompressParams { compressLevel = BestCompression }

decompressWith :: DecompressParams -> ByteString -> ByteString #

Like `decompress` but with the ability to specify various decompression parameters. Typical usage:

    decompressWith defaultCompressParams { ... }

data CompressParams #

The full set of parameters for compression. The defaults are `defaultCompressParams`.

The `compressBufferSize` is the size of the first output buffer containing the compressed data. If you know an approximate upper bound on the size of the compressed data then setting this parameter can save memory. The default compression output buffer size is `16k`. If your estimate is wrong it does not matter too much, the default buffer size will be used for the remaining chunks.

Constructors

CompressParams |
Fields compressLevel :: !CompressionLevel compressMethod :: !Method compressWindowBits :: !WindowBits compressMemoryLevel :: !MemoryLevel compressStrategy :: !CompressionStrategy compressBufferSize :: !Int compressDictionary :: Maybe ByteString

#### Instances

Instances details

Generic CompressParams # |
Instance details Defined in Codec.Compression.Zlib.Internal Associated Types
type Rep CompressParams | Since: zlib-0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal type Rep CompressParams = D1 ('MetaData "CompressParams" "Codec.Compression.Zlib.Internal" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) (C1 ('MetaCons "CompressParams" 'PrefixI 'True) ((S1 ('MetaSel ('Just "compressLevel") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CompressionLevel) :*: (S1 ('MetaSel ('Just "compressMethod") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Method) :*: S1 ('MetaSel ('Just "compressWindowBits") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 WindowBits))) :*: ((S1 ('MetaSel ('Just "compressMemoryLevel") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MemoryLevel) :*: S1 ('MetaSel ('Just "compressStrategy") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CompressionStrategy)) :*: (S1 ('MetaSel ('Just "compressBufferSize") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "compressDictionary") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ByteString))))))
Methods from :: CompressParams -> Rep CompressParams x # to :: Rep CompressParams x -> CompressParams #
Show CompressParams # |
Instance details Defined in Codec.Compression.Zlib.Internal Methods showsPrec :: Int -> CompressParams -> ShowS # show :: CompressParams -> String # showList :: [CompressParams] -> ShowS #
Eq CompressParams # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal Methods (==) :: CompressParams -> CompressParams -> Bool # (/=) :: CompressParams -> CompressParams -> Bool #
Ord CompressParams # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal Methods compare :: CompressParams -> CompressParams -> Ordering # (<) :: CompressParams -> CompressParams -> Bool # (<=) :: CompressParams -> CompressParams -> Bool # (>) :: CompressParams -> CompressParams -> Bool # (>=) :: CompressParams -> CompressParams -> Bool # max :: CompressParams -> CompressParams -> CompressParams # min :: CompressParams -> CompressParams -> CompressParams #
type Rep CompressParams # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal type Rep CompressParams = D1 ('MetaData "CompressParams" "Codec.Compression.Zlib.Internal" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) (C1 ('MetaCons "CompressParams" 'PrefixI 'True) ((S1 ('MetaSel ('Just "compressLevel") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CompressionLevel) :*: (S1 ('MetaSel ('Just "compressMethod") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Method) :*: S1 ('MetaSel ('Just "compressWindowBits") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 WindowBits))) :*: ((S1 ('MetaSel ('Just "compressMemoryLevel") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MemoryLevel) :*: S1 ('MetaSel ('Just "compressStrategy") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CompressionStrategy)) :*: (S1 ('MetaSel ('Just "compressBufferSize") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "compressDictionary") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ByteString))))))

defaultCompressParams :: CompressParams #

The default set of parameters for compression. This is typically used with `compressWith` or `compressWith` with specific parameters overridden.

data DecompressParams #

The full set of parameters for decompression. The defaults are `defaultDecompressParams`.

The `decompressBufferSize` is the size of the first output buffer, containing the uncompressed data. If you know an exact or approximate upper bound on the size of the decompressed data then setting this parameter can save memory. The default decompression output buffer size is `32k`. If your estimate is wrong it does not matter too much, the default buffer size will be used for the remaining chunks.

One particular use case for setting the `decompressBufferSize` is if you know the exact size of the decompressed data and want to produce a strict `ByteString`. The compression and decompression functions use lazy `ByteString`s but if you set the `decompressBufferSize` correctly then you can generate a lazy `ByteString` with exactly one chunk, which can be converted to a strict `ByteString` in `O(1)` time using ``concat` . `toChunks``.

Constructors

DecompressParams |
Fields decompressWindowBits :: !WindowBits decompressBufferSize :: !Int decompressDictionary :: Maybe ByteString decompressAllMembers :: Bool

#### Instances

Instances details

Generic DecompressParams # |
Instance details Defined in Codec.Compression.Zlib.Internal Associated Types
type Rep DecompressParams | Since: zlib-0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal type Rep DecompressParams = D1 ('MetaData "DecompressParams" "Codec.Compression.Zlib.Internal" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) (C1 ('MetaCons "DecompressParams" 'PrefixI 'True) ((S1 ('MetaSel ('Just "decompressWindowBits") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 WindowBits) :*: S1 ('MetaSel ('Just "decompressBufferSize") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "decompressDictionary") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "decompressAllMembers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))
Methods from :: DecompressParams -> Rep DecompressParams x # to :: Rep DecompressParams x -> DecompressParams #
Show DecompressParams # |
Instance details Defined in Codec.Compression.Zlib.Internal Methods showsPrec :: Int -> DecompressParams -> ShowS # show :: DecompressParams -> String # showList :: [DecompressParams] -> ShowS #
Eq DecompressParams # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal Methods (==) :: DecompressParams -> DecompressParams -> Bool # (/=) :: DecompressParams -> DecompressParams -> Bool #
Ord DecompressParams # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal Methods compare :: DecompressParams -> DecompressParams -> Ordering # (<) :: DecompressParams -> DecompressParams -> Bool # (<=) :: DecompressParams -> DecompressParams -> Bool # (>) :: DecompressParams -> DecompressParams -> Bool # (>=) :: DecompressParams -> DecompressParams -> Bool # max :: DecompressParams -> DecompressParams -> DecompressParams # min :: DecompressParams -> DecompressParams -> DecompressParams #
type Rep DecompressParams # | Since: 0.7.0.0
Instance details Defined in Codec.Compression.Zlib.Internal type Rep DecompressParams = D1 ('MetaData "DecompressParams" "Codec.Compression.Zlib.Internal" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) (C1 ('MetaCons "DecompressParams" 'PrefixI 'True) ((S1 ('MetaSel ('Just "decompressWindowBits") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 WindowBits) :*: S1 ('MetaSel ('Just "decompressBufferSize") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "decompressDictionary") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "decompressAllMembers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

defaultDecompressParams :: DecompressParams #

The default set of parameters for decompression. This is typically used with `decompressWith` or `decompressWith` with specific parameters overridden.

## The compression parameter types

newtype CompressionLevel #

The compression level parameter controls the amount of compression. This is a trade-off between the amount of compression and the time required to do the compression.

Constructors

CompressionLevel Int |

#### Instances

Instances details

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

defaultCompression :: CompressionLevel #

The default `CompressionLevel`.

noCompression :: CompressionLevel #

No compression, just a block copy.

bestSpeed :: CompressionLevel #

The fastest compression method (less compression).

bestCompression :: CompressionLevel #

The slowest compression method (best compression).

compressionLevel :: Int -> CompressionLevel #

A specific compression level in the range `0..9`. Throws an error for arguments outside of this range.

- 0 stands for `noCompression`,
- 1 stands for `bestSpeed`,
- 6 stands for `defaultCompression`,
- 9 stands for `bestCompression`.

data Method #

The compression method

#### Instances

Instances details

Bounded Method # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods minBound :: Method # maxBound :: Method #
Enum Method # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods succ :: Method -> Method # pred :: Method -> Method # toEnum :: Int -> Method # fromEnum :: Method -> Int # enumFrom :: Method -> [Method] # enumFromThen :: Method -> Method -> [Method] # enumFromTo :: Method -> Method -> [Method] # enumFromThenTo :: Method -> Method -> Method -> [Method] #
Generic Method # |
Instance details Defined in Codec.Compression.Zlib.Stream Associated Types
type Rep Method |
Instance details Defined in Codec.Compression.Zlib.Stream type Rep Method = D1 ('MetaData "Method" "Codec.Compression.Zlib.Stream" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) (C1 ('MetaCons "Deflated" 'PrefixI 'False) (U1 :: Type -> Type))
Methods from :: Method -> Rep Method x # to :: Rep Method x -> Method #
Show Method # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods showsPrec :: Int -> Method -> ShowS # show :: Method -> String # showList :: [Method] -> ShowS #
Eq Method # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods (==) :: Method -> Method -> Bool # (/=) :: Method -> Method -> Bool #
Ord Method # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods compare :: Method -> Method -> Ordering # (<) :: Method -> Method -> Bool # (<=) :: Method -> Method -> Bool # (>) :: Method -> Method -> Bool # (>=) :: Method -> Method -> Bool # max :: Method -> Method -> Method # min :: Method -> Method -> Method #
type Rep Method # |
Instance details Defined in Codec.Compression.Zlib.Stream type Rep Method = D1 ('MetaData "Method" "Codec.Compression.Zlib.Stream" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) (C1 ('MetaCons "Deflated" 'PrefixI 'False) (U1 :: Type -> Type))

deflateMethod :: Method #

The only method supported in this version of zlib. Indeed it is likely to be the only method that ever will be supported.

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-EzBNMT37lQDL16QGWhFewX" '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-EzBNMT37lQDL16QGWhFewX" '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.

windowBits :: Int -> WindowBits #

A specific compression window size, specified in bits in the range `9..15`. Throws an error for arguments outside of this range.

newtype MemoryLevel #

The `MemoryLevel` parameter specifies how much memory should be allocated for the internal compression state. It is a trade-off between memory usage, compression ratio and compression speed. Using more memory allows faster compression and a better compression ratio.

The total amount of memory used for compression depends on the `WindowBits` and the `MemoryLevel`. For decompression it depends only on the `WindowBits`. The totals are given by the functions:

    compressTotal windowBits memLevel = 4 * 2^windowBits + 512 * 2^memLevel
    decompressTotal windowBits = 2^windowBits

For example, for compression with the default `windowBits = 15` and `memLevel = 8` uses `256Kb`. So for example a network server with 100 concurrent compressed streams would use `25Mb`. The memory per stream can be halved (at the cost of somewhat degraded and slower compression) by reducing the `windowBits` and `memLevel` by one.

Decompression takes less memory, the default `windowBits = 15` corresponds to just `32Kb`.

Constructors

MemoryLevel Int |

#### Instances

Instances details

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

defaultMemoryLevel :: MemoryLevel #

The default `MemoryLevel`. Equivalent to ``memoryLevel` 8`.

minMemoryLevel :: MemoryLevel #

Use minimum memory. This is slow and reduces the compression ratio. Equivalent to ``memoryLevel` 1`.

maxMemoryLevel :: MemoryLevel #

Use maximum memory for optimal compression speed. Equivalent to ``memoryLevel` 9`.

memoryLevel :: Int -> MemoryLevel #

A specific memory level in the range `1..9`. Throws an error for arguments outside of this range.

data CompressionStrategy #

The strategy parameter is used to tune the compression algorithm.

The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately.

#### Instances

Instances details

Bounded CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods minBound :: CompressionStrategy # maxBound :: CompressionStrategy #
Enum CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods succ :: CompressionStrategy -> CompressionStrategy # pred :: CompressionStrategy -> CompressionStrategy # toEnum :: Int -> CompressionStrategy # fromEnum :: CompressionStrategy -> Int # enumFrom :: CompressionStrategy -> [CompressionStrategy] # enumFromThen :: CompressionStrategy -> CompressionStrategy -> [CompressionStrategy] # enumFromTo :: CompressionStrategy -> CompressionStrategy -> [CompressionStrategy] # enumFromThenTo :: CompressionStrategy -> CompressionStrategy -> CompressionStrategy -> [CompressionStrategy] #
Generic CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream Associated Types
type Rep CompressionStrategy |
Instance details Defined in Codec.Compression.Zlib.Stream type Rep CompressionStrategy = D1 ('MetaData "CompressionStrategy" "Codec.Compression.Zlib.Stream" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) ((C1 ('MetaCons "DefaultStrategy" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Filtered" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HuffmanOnly" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "RLE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Fixed" 'PrefixI 'False) (U1 :: Type -> Type))))
Methods from :: CompressionStrategy -> Rep CompressionStrategy x # to :: Rep CompressionStrategy x -> CompressionStrategy #
Show CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods showsPrec :: Int -> CompressionStrategy -> ShowS # show :: CompressionStrategy -> String # showList :: [CompressionStrategy] -> ShowS #
Eq CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods (==) :: CompressionStrategy -> CompressionStrategy -> Bool # (/=) :: CompressionStrategy -> CompressionStrategy -> Bool #
Ord CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream Methods compare :: CompressionStrategy -> CompressionStrategy -> Ordering # (<) :: CompressionStrategy -> CompressionStrategy -> Bool # (<=) :: CompressionStrategy -> CompressionStrategy -> Bool # (>) :: CompressionStrategy -> CompressionStrategy -> Bool # (>=) :: CompressionStrategy -> CompressionStrategy -> Bool # max :: CompressionStrategy -> CompressionStrategy -> CompressionStrategy # min :: CompressionStrategy -> CompressionStrategy -> CompressionStrategy #
type Rep CompressionStrategy # |
Instance details Defined in Codec.Compression.Zlib.Stream type Rep CompressionStrategy = D1 ('MetaData "CompressionStrategy" "Codec.Compression.Zlib.Stream" "zlib-0.7.1.0-EzBNMT37lQDL16QGWhFewX" 'False) ((C1 ('MetaCons "DefaultStrategy" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Filtered" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HuffmanOnly" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "RLE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Fixed" 'PrefixI 'False) (U1 :: Type -> Type))))

defaultStrategy :: CompressionStrategy #

Use this default compression strategy for normal data.

filteredStrategy :: CompressionStrategy #

Use the filtered compression strategy for data produced by a filter (or predictor). Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. The effect of this strategy is to force more Huffman coding and less string matching; it is somewhat intermediate between `defaultStrategy` and `huffmanOnlyStrategy`.

huffmanOnlyStrategy :: CompressionStrategy #

Use the Huffman-only compression strategy to force Huffman encoding only (no string match).

rleStrategy :: CompressionStrategy #

Use `rleStrategy` to limit match distances to one (run-length encoding). `rleStrategy` is designed to be almost as fast as `huffmanOnlyStrategy`, but give better compression for PNG image data.

Since: 0.7.0.0

fixedStrategy :: CompressionStrategy #

`fixedStrategy` prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications.

Since: 0.7.0.0