Compress a stream of data into the raw deflate format.
Modulezlib-0.7.1.0Haskell2010
Codec.Compression.Zlib.Raw
Compression and decompression of data streams in the raw deflate format.
The format is described in detail in RFC #1951: http://www.ietf.org/rfc/rfc1951.txt
See also the zlib home page: http://zlib.net/
- 8 types
- 23 values
- Packagezlib-0.7.1.0
- Exports31
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceRaw.hs
Simple compression and decompression
3 declarationsDecompress a stream of data in the raw deflate format.
The possible error cases when decompressing a stream.
This can be shown to give a human readable error message.
Constructors
TruncatedInputThe compressed data stream ended prematurely. This may happen if the input data stream was truncated.
DictionaryRequiredIt 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.
DictionaryMismatchIf the stream requires a dictionary and you provide one with the wrong
DictionaryHashthen you will get this error.DataFormatError StringIf 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.
Instances6Eq, Ord, Show, Generic, Exception, Rep
Eq DecompressErrorDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalOrd DecompressErrorDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalShow DecompressErrorDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalGeneric DecompressErrorDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalException DecompressErrorDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Internaltype Rep DecompressError = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Internal"DecompressError"
"Codec.Compression.Zlib.Internal"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'False) ((C1 ('MetaCons"TruncatedInput"
'PrefixI 'False) U1 :+: C1 ('MetaCons"DictionaryRequired"
'PrefixI 'False) U1) :+: (C1 ('MetaCons"DictionaryMismatch"
'PrefixI 'False) U1 :+: C1 ('MetaCons"DataFormatError"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))
Extended API with control over compression parameters
6 declarationsLike compress but with the ability to specify various decompression parameters.
Like decompress but with the ability to specify various decompression parameters.
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.
Instances5Eq, Ord, Show, Generic, Rep
Eq CompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalOrd CompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalShow CompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalGeneric CompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Internaltype Rep CompressParams = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Internal"CompressParams"
"Codec.Compression.Zlib.Internal"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'False) (C1 ('MetaCons"CompressParams"
'PrefixI 'True) ((S1 ('MetaSel ('Just"compressLevel"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 CompressionLevel) :*: (S1 ('MetaSel ('Just"compressMethod"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Method) :*: S1 ('MetaSel ('Just"compressWindowBits"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 WindowBits))) :*: ((S1 ('MetaSel ('Just"compressMemoryLevel"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 MemoryLevel) :*: S1 ('MetaSel ('Just"compressStrategy"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CompressionStrategy)) :*: (S1 ('MetaSel ('Just"compressBufferSize"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Int) :*: S1 ('MetaSel ('Just"compressDictionary"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ByteString))))))
The default set of parameters for compression. This is typically used with compressWith or compressWith with specific parameters overridden.
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 ByteStrings 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.
Instances5Eq, Ord, Show, Generic, Rep
Eq DecompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalOrd DecompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalShow DecompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.InternalGeneric DecompressParamsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Internaltype Rep DecompressParams = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Internal"DecompressParams"
"Codec.Compression.Zlib.Internal"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'False) (C1 ('MetaCons"DecompressParams"
'PrefixI 'True) ((S1 ('MetaSel ('Just"decompressWindowBits"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 WindowBits) :*: S1 ('MetaSel ('Just"decompressBufferSize"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Int)) :*: (S1 ('MetaSel ('Just"decompressDictionary"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just"decompressAllMembers"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))
The default set of parameters for decompression. This is typically used with decompressWith or decompressWith with specific parameters overridden.
The compression parameter types
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
Instances5Eq, Ord, Show, Generic, Rep
Eq CompressionLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamOrd CompressionLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamShow CompressionLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamGeneric CompressionLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Streamtype Rep CompressionLevel = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Stream"CompressionLevel"
"Codec.Compression.Zlib.Stream"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'True) (C1 ('MetaCons"CompressionLevel"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
The default CompressionLevel.
No compression, just a block copy.
The fastest compression method (less compression).
The slowest compression method (best compression).
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.
The compression method
Instances7Bounded, Enum, Eq, Ord, Show, Generic, …
Bounded MethodDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamEnum MethodDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamEq MethodDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamOrd MethodDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamShow MethodDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamGeneric MethodDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Streamtype Rep Method = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Stream"Method"
"Codec.Compression.Zlib.Stream"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'False) (C1 ('MetaCons"Deflated"
'PrefixI 'False) U1)
The only method supported in this version of zlib. Indeed it is likely to be the only method that ever will be supported.
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
Instances5Eq, Ord, Show, Generic, Rep
Eq WindowBitsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamOrd WindowBitsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamShow WindowBitsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamGeneric WindowBitsDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Streamtype Rep WindowBits = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Stream"WindowBits"
"Codec.Compression.Zlib.Stream"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'True) (C1 ('MetaCons"WindowBits"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
The default WindowBits. Equivalent to windowBits 15.
which is also the maximum size.
A specific compression window size, specified in bits in the range 9..15.
Throws an error for arguments outside of this range.
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^windowBitsFor 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
Instances5Eq, Ord, Show, Generic, Rep
Eq MemoryLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamOrd MemoryLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamShow MemoryLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamGeneric MemoryLevelDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Streamtype Rep MemoryLevel = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Stream"MemoryLevel"
"Codec.Compression.Zlib.Stream"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'True) (C1 ('MetaCons"MemoryLevel"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
The default MemoryLevel. Equivalent to memoryLevel 8.
Use minimum memory. This is slow and reduces the compression ratio.
Equivalent to memoryLevel 1.
Use maximum memory for optimal compression speed.
Equivalent to memoryLevel 9.
A specific memory level in the range 1..9.
Throws an error for arguments outside of this range.
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.
Instances7Bounded, Enum, Eq, Ord, Show, Generic, …
Bounded CompressionStrategyDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamEnum CompressionStrategyDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamEq CompressionStrategyDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamOrd CompressionStrategyDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamShow CompressionStrategyDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.StreamGeneric CompressionStrategyDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Streamtype Rep CompressionStrategy = D1 ('MetaDataDefined in zlib-0.7.1.0 · Codec.Compression.Zlib.Stream"CompressionStrategy"
"Codec.Compression.Zlib.Stream"
"zlib-0.7.1.0-FdzQBN8c1mMLTBR17egTes"
'False) ((C1 ('MetaCons"DefaultStrategy"
'PrefixI 'False) U1 :+: C1 ('MetaCons"Filtered"
'PrefixI 'False) U1) :+: (C1 ('MetaCons"HuffmanOnly"
'PrefixI 'False) U1 :+: (C1 ('MetaCons"RLE"
'PrefixI 'False) U1 :+: C1 ('MetaCons"Fixed"
'PrefixI 'False) U1)))
Use this default compression strategy for normal data.
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.
Use the Huffman-only compression strategy to force Huffman encoding only (no string match).
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.
fixedStrategy prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications.