zlib-lens-0.1.2.1: Lenses for zlib

Copyright(C) 2012-14 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Codec.Compression.Zlib.Lens

Contents

Description

lens support for the zlib library

Synopsis

High-Level API

gzipped :: Iso' ByteString ByteString #

Compresses a ByteString using the gzip compression format.

gzipped = compressed gzip
gzipped = gzipped' defaultParams

zlibbed :: Iso' ByteString ByteString #

Compresses a ByteString using the zlib compression format.

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

compressed :: Format -> Iso' ByteString ByteString #

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

Bounded Format 
Enum Format 
Eq Format 

Methods

(==) :: Format -> Format -> Bool #

(/=) :: Format -> Format -> Bool #

Ord Format 
Show Format 
Generic Format 

Associated Types

type Rep Format :: * -> * #

Methods

from :: Format -> Rep Format x #

to :: Rep Format x -> Format #

type Rep Format 
type Rep Format = D1 (MetaData "Format" "Codec.Compression.Zlib.Stream" "zlib-0.6.1.2-7negTfm2ujt1gW4wr40MUp" False) ((:+:) ((:+:) (C1 (MetaCons "GZip" PrefixI False) U1) (C1 (MetaCons "Zlib" PrefixI False) U1)) ((:+:) (C1 (MetaCons "Raw" PrefixI False) U1) (C1 (MetaCons "GZipOrZlib" PrefixI False) U1)))

gzip :: Format #

The gzip compression format.

zlib :: Format #

The zlib compression format.

deflate :: Format #

The deflate compression format.

Low-Level API

zlibbed' :: Params -> Iso' ByteString ByteString #

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

zlibbed = compressed zlib
zlibbed = zlibbed' defaultParams

gzipped' :: Params -> Iso' ByteString ByteString #

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

gzipped = compressed gzip
gzipped = gzipped' defaultParams

deflated' :: Params -> Iso' ByteString ByteString #

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 #

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

data Params #

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

Use defaultParams and the provided Lenses to construct custom Params.

defaultParams :: Params #

The default advanced parameters for compression and decompression.

levelC :: Lens' Params CompressionLevel #

The compression level.

methodC :: Lens' Params Method #

The compression method.

windowBitsC :: Lens' Params WindowBits #

The number of bits in the compression window.

windowBitsD :: Lens' Params WindowBits #

The number of bits in the decompression window.

memoryLevelC :: Lens' Params MemoryLevel #

The amount of memory allowed for the internal compression state.

strategyC :: Lens' Params CompressionStrategy #

The compression strategy.

bufferSizeC :: Lens' Params Int #

The initial buffer size during compression.

bufferSizeD :: Lens' Params Int #

The initial buffer size during decompression.

dictionary :: Lens' Params (Maybe ByteString) #

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.

Instances

Eq CompressionLevel 
Show CompressionLevel 
Generic CompressionLevel 
type Rep CompressionLevel 
type Rep CompressionLevel = D1 (MetaData "CompressionLevel" "Codec.Compression.Zlib.Stream" "zlib-0.6.1.2-7negTfm2ujt1gW4wr40MUp" False) ((:+:) ((:+:) (C1 (MetaCons "DefaultCompression" PrefixI False) U1) (C1 (MetaCons "NoCompression" PrefixI False) U1)) ((:+:) (C1 (MetaCons "BestSpeed" PrefixI False) U1) ((:+:) (C1 (MetaCons "BestCompression" PrefixI False) U1) (C1 (MetaCons "CompressionLevel" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))))))

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

Instances

Bounded Method 
Enum Method 
Eq Method 

Methods

(==) :: Method -> Method -> Bool #

(/=) :: Method -> Method -> Bool #

Ord Method 
Show Method 
Generic Method 

Associated Types

type Rep Method :: * -> * #

Methods

from :: Method -> Rep Method x #

to :: Rep Method x -> Method #

type Rep Method 
type Rep Method = D1 (MetaData "Method" "Codec.Compression.Zlib.Stream" "zlib-0.6.1.2-7negTfm2ujt1gW4wr40MUp" False) (C1 (MetaCons "Deflated" PrefixI False) U1)

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.

Instances

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.

Instances

Eq MemoryLevel 
Show MemoryLevel 
Generic MemoryLevel 

Associated Types

type Rep MemoryLevel :: * -> * #

type Rep MemoryLevel 
type Rep MemoryLevel = D1 (MetaData "MemoryLevel" "Codec.Compression.Zlib.Stream" "zlib-0.6.1.2-7negTfm2ujt1gW4wr40MUp" False) ((:+:) ((:+:) (C1 (MetaCons "DefaultMemoryLevel" PrefixI False) U1) (C1 (MetaCons "MinMemoryLevel" PrefixI False) U1)) ((:+:) (C1 (MetaCons "MaxMemoryLevel" PrefixI False) U1) (C1 (MetaCons "MemoryLevel" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)))))

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.

Instances

Bounded CompressionStrategy 
Enum CompressionStrategy 
Eq CompressionStrategy 
Ord CompressionStrategy 
Show CompressionStrategy 
Generic CompressionStrategy 
type Rep CompressionStrategy 
type Rep CompressionStrategy = D1 (MetaData "CompressionStrategy" "Codec.Compression.Zlib.Stream" "zlib-0.6.1.2-7negTfm2ujt1gW4wr40MUp" False) ((:+:) (C1 (MetaCons "DefaultStrategy" PrefixI False) U1) ((:+:) (C1 (MetaCons "Filtered" PrefixI False) U1) (C1 (MetaCons "HuffmanOnly" PrefixI False) U1)))

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