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
This function is deprecated and will be removed in a future
release. Use
Updates a running Adler-32 checksum for
Example:
Crc = lists:foldl(fun(Data,Crc0) -> zlib:adler32(Z, Crc0, Data), end, zlib:adler32(Z,<< >>), Datas)
This function is deprecated and will be removed in a future
release. Use
Combines two Adler-32 checksums into one. For two binaries or
iolists,
This function returns the
This function is deprecated and will be removed in a future
release. Use
Closes the stream referenced by
Compresses data with zlib headers and checksum.
Gets the current calculated CRC checksum.
This function is deprecated and will be removed in a future
release. Use
Calculates the CRC checksum for
This function is deprecated and will be removed in a future
release. Use
Updates a running CRC checksum for
Example:
Crc = lists:foldl(fun(Data,Crc0) -> zlib:crc32(Z, Crc0, Data), end, zlib:crc32(Z,<< >>), Datas)
This function is deprecated and will be removed in a future
release. Use
Combines two CRC checksums into one. For two binaries or iolists,
This function returns the
This function is deprecated and will be removed in a future
release. Use
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 compressor and decompressor must use the same dictionary (see
The Adler checksum of the dictionary is returned.
Gets the size of the intermediate buffer.
This function is deprecated and will be removed in a future release.
Uncompresses data with gz headers and checksum.
Compresses data with gz headers and checksum.
Equivalent to
Decompresses as much data as possible. It can introduce some output latency (reading input without producing any output).
Currently the only available option is
This option defaults to
This function is deprecated and will be removed in a future
release. Use
Reads the next chunk of uncompressed data, initialized by
This function is to be repeatedly called, while it returns
This function is deprecated and will be removed in a future
release. Use
Like
This function returns
This function can introduce some output latency (reading input without producing any output).
An exception will be thrown if a preset dictionary is required for
further decompression. 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
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.
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 as a
response to an inflate operation (eg.
The dictionary chosen by the compressor can be determined from the
Adler value returned or thrown by the call to the inflate function.
The compressor and decompressor must use the same dictionary (See
After setting the dictionary the inflate operation should be retried without new input.
Example:
deprecated_unpack(Z, Compressed, Dict) -> case catch zlib:inflate(Z, Compressed) of {'EXIT',{{need_dictionary,_DictID},_}} -> ok = zlib:inflateSetDictionary(Z, Dict), Uncompressed = zlib:inflate(Z, []); Uncompressed -> Uncompressed end. new_unpack(Z, Compressed, Dict) -> case zlib:inflate(Z, Compressed, [{exception_on_need_dict, false}]) of {need_dictionary, _DictId, Output} -> ok = zlib:inflateSetDictionary(Z, Dict), [Output | zlib:inflate(Z, [])]; Uncompressed -> Uncompressed end.
Opens a zlib stream.
Like
This function returns
This function can introduce some output latency (reading input without producing any output).
If a preset dictionary is required for further decompression, this
function returns a
Example:
walk(Compressed, Handler) -> Z = zlib:open(), zlib:inflateInit(Z), loop(Z, Handler, zlib:safeInflate(Z, Compressed)), zlib:inflateEnd(Z), zlib:close(Z). loop(Z, Handler, {continue, Output}) -> Handler(Output), loop(Z, Handler, zlib:safeInflate(Z, [])); loop(Z, Handler, {finished, Output}) -> Handler(Output).
Sets the intermediate buffer size.
This function is deprecated and will be removed in a future release.
Changes the controlling process of
Uncompresses data with zlib headers and checksum.
Uncompresses data without zlib headers and checksum.
Compresses data without zlib headers and checksum.