The zlib module provides an API for the zlib library (http://www.zlib.org). It is used to compress and decompress data. The data format is described by RFCs 1950 to 1952.
A typical (compress) usage looks like:
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,
Bad argument
The data contains errors
Inconsistent stream state
Bad value or wrong function called
See
A zlib stream, see
Normally in the range
Open a zlib stream.
Closes the stream referenced by
Same as
Initialize a zlib stream for compression.
Initiates a zlib stream for compression.
The
The
The
The
The
Same as
If the parameter
If
If the parameter
zlib:deflateInit(Z), B1 = zlib:deflate(Z,Data), B2 = zlib:deflate(Z,<< >>,finish), zlib:deflateEnd(Z), list_to_binary([B1,B2])
Initializes the compression dictionary from the given byte
sequence without producing any compressed output. This
function must be called immediately after
This function is equivalent to
Dynamically update the compression level and compression
strategy. The interpretation of
Before the call of
End the deflate session and cleans all data used.
Note that this function will throw an
Initialize a zlib stream for decompression.
Initialize decompression session on zlib stream.
The
If a preset dictionary is needed at this point (see
Initializes the decompression dictionary from the given
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.
This function is equivalent to
End the inflate session and cleans all data used. Note
that this function will throw a
Sets the intermediate buffer size.
Get the size of intermediate buffer.
Get the current calculated CRC checksum.
Calculate the CRC checksum for
Update a running CRC checksum for
Crc = lists:foldl(fun(Data,Crc0) -> zlib:crc32(Z, Crc0, Data), end, zlib:crc32(Z,<< >>), Datas)
Combine two CRC checksums into one. For two binaries or iolists,
Calculate the Adler-32 checksum for
Update a running Adler-32 checksum for
Crc = lists:foldl(fun(Data,Crc0) -> zlib:adler32(Z, Crc0, Data), end, zlib:adler32(Z,<< >>), Datas)
Combine two Adler-32 checksums into one. For two binaries or iolists,
Compress data (with zlib headers and checksum).
Uncompress data (with zlib headers and checksum).
Compress data (without zlib headers and checksum).
Uncompress data (without zlib headers and checksum).
Compress data (with gz headers and checksum).
Uncompress data (with gz headers and checksum).