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
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,
Closes the stream referenced by
Compress data (with zlib headers and checksum).
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,
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])
End the deflate session and cleans all data used.
Note that this function will throw an
Same as
Initialize a zlib stream for compression.
Initiates a zlib stream for compression.
The
The
The
The
The
Dynamically update the compression level and compression
strategy. The interpretation of
Before the call of
This function is equivalent to
Initializes the compression dictionary from the given byte
sequence without producing any compressed output. This
function must be called immediately after
Get the size of intermediate buffer.
Uncompress data (with gz headers and checksum).
Compress data (with gz headers and checksum).
If a preset dictionary is needed at this point (see
Read next chunk of uncompressed data, initialized by
This function should be repeatedly called, while it returns
Like
If a preset dictionary is needed at this point (see
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).
End the inflate session and cleans all data used. Note
that this function will throw a
Initialize a zlib stream for decompression.
Initialize decompression session on zlib stream.
The
This function is equivalent to
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.
Open a zlib stream.
Sets the intermediate buffer size.
Uncompress data (with zlib headers and checksum).
Uncompress data (without zlib headers and checksum).
Compress data (without zlib headers and checksum).