Copyright | (C) 2012-14 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
lens
support for the zlib
library
- gzipped :: Iso' ByteString ByteString
- zlibbed :: Iso' ByteString ByteString
- deflated :: Iso' ByteString ByteString
- compressed :: Format -> Iso' ByteString ByteString
- data Format :: *
- gzip :: Format
- zlib :: Format
- deflate :: Format
- zlibbed' :: Params -> Iso' ByteString ByteString
- gzipped' :: Params -> Iso' ByteString ByteString
- deflated' :: Params -> Iso' ByteString ByteString
- compressed' :: Format -> Params -> Iso' ByteString ByteString
- data Params
- defaultParams :: Params
- levelC :: Lens' Params CompressionLevel
- methodC :: Lens' Params Method
- windowBitsC :: Lens' Params WindowBits
- windowBitsD :: Lens' Params WindowBits
- memoryLevelC :: Lens' Params MemoryLevel
- strategyC :: Lens' Params CompressionStrategy
- bufferSizeC :: Lens' Params Int
- bufferSizeD :: Lens' Params Int
- dictionary :: Lens' Params (Maybe ByteString)
- data CompressionLevel :: *
- defaultCompression :: CompressionLevel
- noCompression :: CompressionLevel
- bestSpeed :: CompressionLevel
- bestCompression :: CompressionLevel
- compressionLevel :: Int -> CompressionLevel
- data Method :: *
- deflateMethod :: Method
- data WindowBits :: *
- defaultWindowBits :: WindowBits
- windowBits :: Int -> WindowBits
- data MemoryLevel :: *
- defaultMemoryLevel :: MemoryLevel
- minMemoryLevel :: MemoryLevel
- maxMemoryLevel :: MemoryLevel
- memoryLevel :: Int -> MemoryLevel
- data CompressionStrategy :: *
- defaultStrategy :: CompressionStrategy
- filteredStrategy :: CompressionStrategy
- huffmanOnlyStrategy :: CompressionStrategy
High-Level API
gzipped :: Iso' ByteString ByteString Source
Compresses a ByteString
using the gzip
compression format.
gzipped
=compressed
gzip
gzipped
=gzipped'
defaultParams
zlibbed :: Iso' ByteString ByteString Source
Compresses a ByteString
using the zlib
compression format.
zlibbed
=compressed
zlib
zlibbed
= 'zlibbed\''defaultParams
deflated :: Iso' ByteString ByteString Source
Compresses a ByteString
using the deflate
compression format.
deflated
=compressed
deflate
deflated
=deflated'
defaultParams
compressed :: Format -> Iso' ByteString ByteString Source
Compresses a ByteString
using the given compression format.
compressed
fmt =compressed'
fmtdefaultParams
data Format :: *
The format used for compression or decompression. There are three variations.
Low-Level API
zlibbed' :: Params -> Iso' ByteString ByteString Source
Compresses a ByteString
using the zlib
compression format and the given advanced parameters.
zlibbed
=compressed
zlib
zlibbed
=zlibbed'
defaultParams
gzipped' :: Params -> Iso' ByteString ByteString Source
Compresses a ByteString
using the gzip
compression format and the given advanced parameters.
gzipped
=compressed
gzip
gzipped
=gzipped'
defaultParams
deflated' :: Params -> Iso' ByteString ByteString Source
Compresses a ByteString
using the deflate
compression format and the given advanced parameters.
deflated
=compressed
deflate
deflated
=deflated'
defaultParams
compressed' :: Format -> Params -> Iso' ByteString ByteString Source
Compresses a ByteString
using the given compression format and the given advanced parameters.
The advanced parameters needed by gzipped'
, zlibbed'
, deflated'
, and compressed'
.
Use defaultParams
and the provided Lens
es to construct custom Params
.
defaultParams :: Params Source
The default advanced parameters for compression and decompression.
levelC :: Lens' Params CompressionLevel Source
The compression level.
windowBitsC :: Lens' Params WindowBits Source
The number of bits in the compression window.
windowBitsD :: Lens' Params WindowBits Source
The number of bits in the decompression window.
memoryLevelC :: Lens' Params MemoryLevel Source
The amount of memory allowed for the internal compression state.
strategyC :: Lens' Params CompressionStrategy Source
The compression strategy.
bufferSizeC :: Lens' Params Int Source
The initial buffer size during compression.
bufferSizeD :: Lens' Params Int Source
The initial buffer size during decompression.
dictionary :: Lens' Params (Maybe ByteString) Source
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.
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
'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
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
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).