This module provides an API for the zlib library
(
A typical (compress) usage is as follows:
Z = zlib:open(), ok = zlib:deflateInit(Z,default), Compress = fun(end_of_data, _Cont) -> []; (Data, Cont) -> [zlib:deflate(Z, Data)|Cont(Read(),Cont)] end, Compressed = Compress(Read(),Compress), Last = zlib:deflate(Z, [], finish), ok = zlib:deflateEnd(Z), zlib:close(Z), list_to_binary([Compressed|Last])
In all functions errors,
Typical
A zlib stream, see
Normally in the range
Calculates the Adler-32 checksum for
Updates a running Adler-32 checksum for
Example:
Crc = lists:foldl(fun(Data,Crc0) -> zlib:adler32(Z, Crc0, Data), end, zlib:adler32(Z,<< >>), Datas)
Combines two Adler-32 checksums into one. For two binaries or
iolists,
This function returns the
Closes the stream referenced by
Compresses data with zlib headers and checksum.
Gets the current calculated CRC checksum.
Calculates the CRC checksum for
Updates a running CRC checksum for
Example:
Crc = lists:foldl(fun(Data,Crc0) -> zlib:crc32(Z, Crc0, Data), end, zlib:crc32(Z,<< >>), Datas)
Combines two CRC checksums into one. For two binaries or iolists,
This function returns the
Same as
Compresses as much data as possible, and stops when the input buffer becomes empty. It can introduce some output latency (reading input without producing any output) except when forced to flush.
If
If
If
Example:
zlib:deflateInit(Z), B1 = zlib:deflate(Z,Data), B2 = zlib:deflate(Z,<< >>,finish), zlib:deflateEnd(Z), list_to_binary([B1,B2])
Ends the deflate session and cleans all data used. Notice that this
function throws a
Same as
Initializes a zlib stream for compression.
Initiates a zlib stream for compression.
Compression level to use:
Compression method to use, currently the only supported method
is
The base two logarithm of the window size (the size of the
history buffer). It is to be in the range 8 through 15. Larger
values result in better compression at the expense of memory
usage. Defaults to 15 if
Due to a known bug in the underlying zlib library,
Conclusion: Avoid values 8 and -8 unless you know your zlib version supports them.
Specifies how much memory is to be allocated for the internal
compression state:
Tunes the compression algorithm. Use the following values:
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
Dynamically updates the compression level and compression
strategy. The interpretation of
Before the call of
Equivalent to
Initializes the compression dictionary from the specified byte sequence without producing any compressed output.
This function must be called immediately after
The Adler checksum of the dictionary is returned.
Gets the size of the intermediate buffer.
Uncompresses data with gz headers and checksum.
Compresses data with gz headers and checksum.
Decompresses as much data as possible. It can introduce some output latency (reading input without producing any output).
If a preset dictionary is needed at this point (see
Reads the next chunk of uncompressed data, initialized by
This function is to be repeatedly called, while it returns
Like
This function returns
This function can introduce some output latency (reading input without producing any output).
If a preset dictionary is needed at this point (see
Example:
walk(Compressed, Handler) -> Z = zlib:open(), zlib:inflateInit(Z), % Limit single uncompressed chunk size to 512kb zlib:setBufSize(Z, 512 * 1024), loop(Z, Handler, zlib:inflateChunk(Z, Compressed)), zlib:inflateEnd(Z), zlib:close(Z). loop(Z, Handler, {more, Uncompressed}) -> Handler(Uncompressed), loop(Z, Handler, zlib:inflateChunk(Z)); loop(Z, Handler, Uncompressed) -> Handler(Uncompressed).
Ends the inflate session and cleans all data used. Notice
that this function throws a
Initializes a zlib stream for decompression.
Initializes a decompression session on zlib stream.
If a compressed stream with a larger window size is specified as
input,
A negative
Equivalent to
Initializes the decompression dictionary from the specified
uncompressed byte sequence. This function must be called
immediately after a call of
Example:
unpack(Z, Compressed, Dict) -> case catch zlib:inflate(Z, Compressed) of {'EXIT',{{need_dictionary,DictID},_}} -> zlib:inflateSetDictionary(Z, Dict), Uncompressed = zlib:inflate(Z, []); Uncompressed -> Uncompressed end.
Returns the decompression dictionary currently in use
by the stream. This function must be called between
Only supported if ERTS was compiled with zlib >= 1.2.8.
Opens a zlib stream.
Sets the intermediate buffer size.
Uncompresses data with zlib headers and checksum.
Uncompresses data without zlib headers and checksum.
Compresses data without zlib headers and checksum.