ZLIB
Loading...
Searching...
No Matches
Utility Functions

The following utility functions are implemented on top of the basic stream-oriented functions. More...

Functions

int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
 Compresses the source buffer into the destination buffer.
 
int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
 Compresses the source buffer into the destination buffer.
 
uLong ZEXPORT compressBound (uLong sourceLen)
 Returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes.
 
int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
 Decompresses the source buffer into the destination buffer.
 
int ZEXPORT uncompress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
 Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen.
 

Detailed Description

The following utility functions are implemented on top of the basic stream-oriented functions.

To simplify the interface, some default options are assumed (compression level and memory usage, standard memory allocation functions). The source code of these utility functions can be modified if you need special options.

Function Documentation

◆ compress()

int ZEXPORT compress ( Bytef *  dest,
uLongf *  destLen,
const Bytef *  source,
uLong  sourceLen 
)

Compresses the source buffer into the destination buffer.

sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least the value returned by compressBound(sourceLen). Upon exit, destLen is the actual size of the compressed data. compress() is equivalent to compress2() with a level parameter of Z_DEFAULT_COMPRESSION.

compress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer.

◆ compress2()

int ZEXPORT compress2 ( Bytef *  dest,
uLongf *  destLen,
const Bytef *  source,
uLong  sourceLen,
int  level 
)

Compresses the source buffer into the destination buffer.

The level parameter has the same meaning as in deflateInit. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least the value returned by compressBound(sourceLen). Upon exit, destLen is the actual size of the compressed data.

compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid.

◆ compressBound()

uLong ZEXPORT compressBound ( uLong  sourceLen)

Returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes.

It would be used before a compress() or compress2() call to allocate the destination buffer.

If the default memLevel or windowBits for deflateInit() is changed, then this function needs to be updated.

◆ uncompress()

int ZEXPORT uncompress ( Bytef *  dest,
uLongf *  destLen,
const Bytef *  source,
uLong  sourceLen 
)

Decompresses the source buffer into the destination buffer.

sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the actual size of the uncompressed data.

uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In the case where there is not enough room, uncompress() will fill the output buffer with the uncompressed data up to that point.

◆ uncompress2()

int ZEXPORT uncompress2 ( Bytef *  dest,
uLongf *  destLen,
const Bytef *  source,
uLong *  sourceLen 
)

Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen.

On return, *sourceLen is the number of source bytes consumed.

Decompresses the source buffer into the destination buffer. *sourceLen is the byte length of the source buffer. Upon entry, *destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the size of the decompressed data and *sourceLen is the number of source bytes consumed. Upon return, source + *sourceLen points to the first unused input byte.

uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, or Z_DATA_ERROR if the input data was corrupted, including if the input data is an incomplete zlib stream.