| |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
Description | |||||||||||||||||||
Compression and decompression of data streams in the gzip format. The format is described in detail in RFC #1952: http://www.ietf.org/rfc/rfc1952.txt See also the zlib home page: http://zlib.net/ | |||||||||||||||||||
Synopsis | |||||||||||||||||||
Documentation | |||||||||||||||||||
This module provides pure functions for compressing and decompressing streams of data in the gzip format and represented by lazy ByteStrings. This makes it easy to use either in memory or with disk or network IO. For example a simple gzip compression program is just: import qualified Data.ByteString.Lazy as ByteString import qualified Codec.Compression.GZip as GZip main = ByteString.interact GZip.compress Or you could lazily read in and decompress a .gz file using: content <- fmap GZip.decompress (readFile file) | |||||||||||||||||||
Simple compression and decompression | |||||||||||||||||||
compress :: ByteString -> ByteString | |||||||||||||||||||
Compress a stream of data into the gzip format. This uses the default compression parameters. In partiular 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 gzip format. There are a number of errors that can occur. In each case an exception will be thrown. The possible error conditions are:
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. | |||||||||||||||||||
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 | |||||||||||||||||||
| |||||||||||||||||||
defaultCompressParams :: CompressParams | |||||||||||||||||||
The default set of parameters for compression. This is typically used with the compressWith function with specific parameters overridden. | |||||||||||||||||||
data DecompressParams | |||||||||||||||||||
| |||||||||||||||||||
defaultDecompressParams :: DecompressParams | |||||||||||||||||||
The default set of parameters for decompression. This is typically used with the compressWith function with specific parameters overridden. | |||||||||||||||||||
The compression parameter types | |||||||||||||||||||
data CompressionLevel | |||||||||||||||||||
| |||||||||||||||||||
defaultCompression :: CompressionLevel | |||||||||||||||||||
The default compression level is 6 (that is, biased towards higher compression at expense of speed). | |||||||||||||||||||
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 between 0 and 9. | |||||||||||||||||||
data Method | |||||||||||||||||||
| |||||||||||||||||||
deflateMethod :: Method | |||||||||||||||||||
'Deflate' is the only method supported in this version of zlib. Indeed it is likely to be the only method that ever will be supported. | |||||||||||||||||||
data WindowBits | |||||||||||||||||||
| |||||||||||||||||||
defaultWindowBits :: WindowBits | |||||||||||||||||||
The default WindowBits is 15 which is also the maximum size. | |||||||||||||||||||
windowBits :: Int -> WindowBits | |||||||||||||||||||
A specific compression window size, specified in bits in the range 8..15 | |||||||||||||||||||
data MemoryLevel | |||||||||||||||||||
| |||||||||||||||||||
defaultMemoryLevel :: MemoryLevel | |||||||||||||||||||
The default memory level. (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 level in the range 1..9 | |||||||||||||||||||
data CompressionStrategy | |||||||||||||||||||
| |||||||||||||||||||
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 defaultCompressionStrategy and huffmanOnlyCompressionStrategy. | |||||||||||||||||||
huffmanOnlyStrategy :: CompressionStrategy | |||||||||||||||||||
Use the Huffman-only compression strategy to force Huffman encoding only (no string match). | |||||||||||||||||||
Produced by Haddock version 2.6.0 |