lens-4.3.1: Lenses, Folds and Traversals

Portabilityportable
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellNone

Codec.Compression.Zlib.Lens

Contents

Description

lens support for the zlib library

Synopsis

High-Level API

zlibbed :: Iso' ByteString ByteStringSource

Compresses a ByteString using the zlib compression format.

 zlibbed = compressed zlib
 zlibbed = 'zlibbed\'' defaultParams

compressed :: Format -> Iso' ByteString ByteStringSource

Compresses a ByteString using the given compression format.

 compressed fmt = compressed' fmt defaultParams

data Format

The format used for compression or decompression. There are three variations.

Instances

gzip :: FormatSource

The gzip compression format.

zlib :: FormatSource

The zlib compression format.

deflate :: FormatSource

The deflate compression format.

Low-Level API

zlibbed' :: Params -> Iso' ByteString ByteStringSource

Compresses a ByteString using the zlib compression format and the given advanced parameters.

 zlibbed = compressed zlib
 zlibbed = zlibbed' defaultParams

gzipped' :: Params -> Iso' ByteString ByteStringSource

Compresses a ByteString using the gzip compression format and the given advanced parameters.

 gzipped = compressed gzip
 gzipped = gzipped' defaultParams

deflated' :: Params -> Iso' ByteString ByteStringSource

Compresses a ByteString using the deflate compression format and the given advanced parameters.

 deflated = compressed deflate
 deflated = deflated' defaultParams

compressed' :: Format -> Params -> Iso' ByteString ByteStringSource

Compresses a ByteString using the given compression format and the given advanced parameters.

data Params Source

The advanced parameters needed by gzipped', zlibbed', deflated', and compressed'.

Use defaultParams and the provided Lenses to construct custom Params.

defaultParams :: ParamsSource

The default advanced parameters for compression and decompression.

levelC :: Lens' Params CompressionLevelSource

The compression level.

methodC :: Lens' Params MethodSource

The compression method.

windowBitsC :: Lens' Params WindowBitsSource

The number of bits in the compression window.

windowBitsD :: Lens' Params WindowBitsSource

The number of bits in the decompression window.

memoryLevelC :: Lens' Params MemoryLevelSource

The amount of memory allowed for the internal compression state.

strategyC :: Lens' Params CompressionStrategySource

The compression strategy.

bufferSizeC :: Lens' Params IntSource

The initial buffer size during compression.

bufferSizeD :: Lens' Params IntSource

The initial buffer size during decompression.

dictionary :: Lens' Params (Maybe ByteString)Source

Just the custom (de)compression dictionary to use, or Nothing to not use a custom dictionary.

data 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.

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

The compression 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

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 8..15 which corresponds to compression window sizes of 256b 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.

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

The MemoryLevel parameter specifies how much memory should be allocated for the internal compression state. It is a tradoff 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 compressionby) by reducing the windowBits and memLevel by one.

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

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

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.

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).