ZLIB
Loading...
Searching...
No Matches
zlib.h File Reference

interface of the `zlib` More...

#include "zconf.h"

Go to the source code of this file.

Data Structures

struct  z_stream
 Compressed stream state information. More...
 
struct  gz_header
 gzip header information passed to and from zlib routines. More...
 
struct  gzFile
 Semi-opaque gzip file descriptor structure. More...
 

Macros

#define Z_DEFLATED   8
 The deflate compression method (the only one supported in this version)
 
#define Z_NULL   0
 for initializing zalloc, zfree, opaque
 
#define zlib_version   zlibVersion()
 for compatibility with versions < 1.0.2
 
#define deflateInit(strm, level)    deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
 
#define inflateInit(strm)    inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
 
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
 Macro wrapper of deflateInit2_() allows checking the zlib version and the compiler's view of z_stream.
 
#define inflateInit2(strm, windowBits)
 Macro wrapper of inflateInit2_() allows checking the zlib version and the compiler's view of z_stream.
 
#define inflateBackInit(strm, windowBits, window)
 Macro wrapper of inflateBackInit_() allows checking the zlib version and the compiler's view of z_stream.
 
#define gzgetc(g)    ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
 
Version information
#define ZLIB_VERSION   "1.3.0.f-neacsum"
 zlib version information string
 
#define ZLIB_VERNUM   0x130f
 Complete version number.
 
#define ZLIB_VER_MAJOR   1
 Major version number.
 
#define ZLIB_VER_MINOR   3
 Minor version number.
 
#define ZLIB_VER_REVISION   0
 Revision major number.
 
#define ZLIB_VER_SUBREVISION   f
 Revision minor number.
 
Allowed flush values

See deflate() and inflate() for details

#define Z_NO_FLUSH   0
 
#define Z_PARTIAL_FLUSH   1
 
#define Z_SYNC_FLUSH   2
 
#define Z_FULL_FLUSH   3
 
#define Z_FINISH   4
 
#define Z_BLOCK   5
 
#define Z_TREES   6
 
Return codes for the compression/decompression functions.

Negative values are errors, positive values are used for special but normal events.

#define Z_OK   0
 Success.
 
#define Z_STREAM_END   1
 End of input or output stream.
 
#define Z_NEED_DICT   2
 
#define Z_ERRNO   (-1)
 
#define Z_STREAM_ERROR   (-2)
 Inconsistent stream state.
 
#define Z_DATA_ERROR   (-3)
 Invalid input data.
 
#define Z_MEM_ERROR   (-4)
 Out of memeory.
 
#define Z_BUF_ERROR   (-5)
 Buffer full error.
 
#define Z_VERSION_ERROR   (-6)
 Library version mismatch.
 
Compression levels
#define Z_NO_COMPRESSION   0
 
#define Z_BEST_SPEED   1
 
#define Z_BEST_COMPRESSION   9
 
#define Z_DEFAULT_COMPRESSION   (-1)
 
Compression strategy; see deflateInit2() below for details
#define Z_FILTERED   1
 
#define Z_HUFFMAN_ONLY   2
 
#define Z_RLE   3
 
#define Z_FIXED   4
 
#define Z_DEFAULT_STRATEGY   0
 
Possible values of the data_type field for deflate()
#define Z_BINARY   0
 
#define Z_TEXT   1
 
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
 
#define Z_UNKNOWN   2
 

Typedefs

typedef z_streamz_streamp
 
typedef gz_headergz_headerp
 
typedef unsigned(* in_func) (void *, const unsigned char **)
 Input function used by inflateBack()
 
typedef int(* out_func) (void *, unsigned char *, unsigned)
 Output function used by inflateBack()
 
Memory management functions

The opaque value provided by the application will be passed as the first parameter for calls of z_stream::zalloc and z_stream::zfree.

This can be useful for custom memory management. The compression library attaches no meaning to the opaque value.

typedef voidpf(* alloc_func) (voidpf opaque, uInt items, uInt size)
 
typedef void(* free_func) (voidpf opaque, voidpf address)
 

Functions

const char *ZEXPORT zlibVersion (void)
 The application can compare zlibVersion and ZLIB_VERSION for consistency.
 
int ZEXPORT deflate (z_streamp strm, int flush)
 Compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full.
 
int ZEXPORT deflateEnd (z_streamp strm)
 All dynamically allocated data structures for this stream are freed.
 
int ZEXPORT inflate (z_streamp strm, int flush)
 Decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full.
 
int ZEXPORT inflateEnd (z_streamp strm)
 All dynamically allocated data structures for this stream are freed.
 
int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
 Initializes the compression dictionary from the given byte sequence without producing any compressed output.
 
int ZEXPORT deflateGetDictionary (z_streamp strm, Bytef *dictionary, uInt *dictLength)
 Returns the sliding dictionary being maintained by deflate.
 
int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
 Sets the destination stream as a complete copy of the source stream.
 
int ZEXPORT deflateReset (z_streamp strm)
 This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state.
 
int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
 Dynamically update the compression level and compression strategy.
 
int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
 Fine tune deflate's internal compression parameters.
 
uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
 Returns an upper bound on the compressed size after deflation of sourceLen bytes.
 
int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, int *bits)
 Returns the number of bytes and bits of output that have been generated, but not yet provided in the available output.
 
int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
 Inserts bits in the deflate output stream.
 
int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
 Provides gzip header information for when a gzip stream is requested by deflateInit2().
 
int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
 Initializes the decompression dictionary from the given uncompressed byte sequence.
 
int ZEXPORT inflateGetDictionary (z_streamp strm, Bytef *dictionary, uInt *dictLength)
 Returns the sliding dictionary being maintained by inflate.
 
int ZEXPORT inflateSync (z_streamp strm)
 Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all available input is skipped.
 
ZEXTERN int ZEXPORT inflateCopy (z_streamp dest, z_streamp source)
 Sets the destination stream as a complete copy of the source stream.
 
int ZEXPORT inflateReset (z_streamp strm)
 This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state.
 
int ZEXPORT inflateReset2 (z_streamp strm, int windowBits)
 This function is the same as inflateReset, but it also permits changing the wrap and window size requests.
 
int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
 This function inserts bits in the inflate input stream.
 
long ZEXPORT inflateMark (z_streamp strm)
 This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the return value down 16 bits.
 
int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
 Requests that gzip header information be stored in the provided gz_header structure.
 
int ZEXPORT inflateBack (z_streamp strm, in_func in, void *in_desc, out_func out, void *out_desc)
 Does a raw inflate with a single call using a call-back interface for input and output.
 
int ZEXPORT inflateBackEnd (z_streamp strm)
 All memory allocated by inflateBackInit() is freed.
 
uLong ZEXPORT zlibCompileFlags (void)
 Return flags indicating compile-time options.
 
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.
 
gzFile ZEXPORT gzdopen (int fd, const char *mode)
 Associate a gzFile with the file descriptor fd.
 
int ZEXPORT gzbuffer (gzFile file, unsigned size)
 Set the internal buffer size used by this library's functions for file to size.
 
int ZEXPORT gzsetparams (gzFile file, int level, int strategy)
 Dynamically update the compression level and strategy for file.
 
int ZEXPORT gzread (gzFile file, voidp buf, unsigned len)
 Read and decompress up to len uncompressed bytes from file into buf.
 
z_size_t ZEXPORT gzfread (voidp buf, z_size_t size, z_size_t nitems, gzFile file)
 Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does.
 
int ZEXPORT gzwrite (gzFile file, voidpc buf, unsigned len)
 Compress and write the len uncompressed bytes at buf to file.
 
z_size_t ZEXPORT gzfwrite (voidpc buf, z_size_t size, z_size_t nitems, gzFile file)
 Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types.
 
int ZEXPORTVA gzprintf (gzFile file, const char *format,...)
 
int ZEXPORT gzputs (gzFile file, const char *s)
 Compress and write the given null-terminated string s to file, excluding the terminating null character.
 
char *ZEXPORT gzgets (gzFile file, char *buf, int len)
 Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an end-of-file condition is encountered.
 
int ZEXPORT gzputc (gzFile file, int c)
 Compress and write c, converted to an unsigned char, into file.
 
int ZEXPORT gzgetc (gzFile file)
 Read and decompress one byte from file.
 
int ZEXPORT gzungetc (int c, gzFile file)
 Push c back onto the stream for file to be read as the first character on the next read.
 
int ZEXPORT gzflush (gzFile file, int flush)
 Flush all pending output to file.
 
int ZEXPORT gzrewind (gzFile file)
 Rewind file.
 
int ZEXPORT gzeof (gzFile file)
 Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise.
 
int ZEXPORT gzdirect (gzFile file)
 Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed.
 
int ZEXPORT gzclose (gzFile file)
 Flush all pending output for file, if necessary, close file and deallocate the (de)compression state.
 
int ZEXPORT gzclose_r (gzFile file)
 Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending.
 
int ZEXPORT gzclose_w (gzFile file)
 Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending.
 
const char *ZEXPORT gzerror (gzFile file, int *errnum)
 Return the error message for the last error which occurred on file.
 
ZEXTERN void ZEXPORT gzclearerr (gzFile file)
 Clear the error and end-of-file flags for file.
 
uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len)
 Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum.
 
uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, z_size_t len)
 Same as adler32(), but with a size_t length.
 
uLong ZEXPORT crc32 (uLong crc, const Bytef *buf, uInt len)
 
uLong ZEXPORT crc32_z (uLong crc, const Bytef *buf, z_size_t len)
 
ZEXTERN uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op)
 Give the same result as crc32_combine(), using op in place of len2.
 
ZEXTERN int ZEXPORT deflateInit_ (z_streamp strm, int level, const char *version, int stream_size)
 Initializes the internal stream state for compression.
 
int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
 Initializes the internal stream state for decompression.
 
int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
 Another version of deflateInit() with more compression options.
 
int ZEXPORT inflateInit2_ (z_streamp strm, int windowBits, const char *version, int stream_size)
 This is another version of inflateInit with an extra parameter.
 
int ZEXPORT inflateBackInit_ (z_streamp strm, int windowBits, unsigned char *window, const char *version, int stream_size)
 Initialize the internal stream state for decompression using inflateBack() calls.
 
ZEXTERN int ZEXPORT gzgetc_ (gzFile file)
 
gzFile ZEXPORT gzopen (const char *, const char *)
 Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing.
 
z_off_t ZEXPORT gzseek (gzFile, z_off_t, int)
 Set the starting position to offset relative to whence for the next gzread or gzwrite on file.
 
z_off_t ZEXPORT gztell (gzFile)
 Return the starting position for the next gzread or gzwrite on file.
 
z_off_t ZEXPORT gzoffset (gzFile)
 Return the current compressed (actual) read or write offset of file.
 
ZEXTERN uLong ZEXPORT adler32_combine (uLong, uLong, z_off_t)
 
ZEXTERN uLong ZEXPORT crc32_combine (uLong, uLong, z_off_t)
 Combine two CRC-32 check values into one.
 
ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t)
 
ZEXTERN const char *ZEXPORT zError (int)
 Exported to allow conversion of error code to string for compress() and uncompress()
 
ZEXTERN int ZEXPORT inflateSyncPoint (z_streamp)
 
ZEXTERN const z_crc_t *ZEXPORT get_crc_table (void)
 
ZEXTERN int ZEXPORT inflateUndermine (z_streamp, int)
 
ZEXTERN int ZEXPORT inflateValidate (z_streamp, int)
 
ZEXTERN unsigned long ZEXPORT inflateCodesUsed (z_streamp)
 
ZEXTERN int ZEXPORT inflateResetKeep (z_streamp)
 
ZEXTERN int ZEXPORT deflateResetKeep (z_streamp)
 

Detailed Description

interface of the `zlib`

Macro Definition Documentation

◆ deflateInit2

#define deflateInit2 (   strm,
  level,
  method,
  windowBits,
  memLevel,
  strategy 
)
Value:
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, (int)sizeof(z_stream))
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
Another version of deflateInit() with more compression options.
Definition deflate.c:495
Compressed stream state information.
Definition zlib.h:136
#define ZLIB_VERSION
zlib version information string
Definition zlib.h:79

Macro wrapper of deflateInit2_() allows checking the zlib version and the compiler's view of z_stream.

◆ inflateBackInit

#define inflateBackInit (   strm,
  windowBits,
  window 
)
Value:
inflateBackInit_((strm), (windowBits), (window), \
ZLIB_VERSION, (int)sizeof(z_stream))
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char *window, const char *version, int stream_size)
Initialize the internal stream state for decompression using inflateBack() calls.
Definition infback.c:47

Macro wrapper of inflateBackInit_() allows checking the zlib version and the compiler's view of z_stream.

◆ inflateInit2

#define inflateInit2 (   strm,
  windowBits 
)
Value:
inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
(int)sizeof(z_stream))
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
This is another version of inflateInit with an extra parameter.
Definition inflate.c:266

Macro wrapper of inflateInit2_() allows checking the zlib version and the compiler's view of z_stream.

◆ ZLIB_VERSION

#define ZLIB_VERSION   "1.3.0.f-neacsum"

zlib version information string

Version information string

Function Documentation

◆ adler32()

uLong ZEXPORT adler32 ( uLong  adler,
const Bytef *  buf,
uInt  len 
)

Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum.

An Adler-32 value is in the range of a 32-bit unsigned integer. If buf is Z_NULL, this function returns the required initial value for the checksum.

An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed much faster.

Usage example:

uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum.
Definition adler32.c:153
#define Z_NULL
for initializing zalloc, zfree, opaque
Definition zlib.h:245

◆ crc32_combine()

ZEXTERN uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Combine two CRC-32 check values into one.

For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and len2.

◆ crc32_combine_op()

ZEXTERN uLong ZEXPORT crc32_combine_op ( uLong  crc1,
uLong  crc2,
uLong  op 
)

Give the same result as crc32_combine(), using op in place of len2.

op is is generated from len2 by crc32_combine_gen(). This will be faster than crc32_combine() if the generated op is used more than once.

◆ deflateInit_()

ZEXTERN int ZEXPORT deflateInit_ ( z_streamp  strm,
int  level,
const char *  version,
int  stream_size 
)

Initializes the internal stream state for compression.

Parameters
strmpointrer to compressed stream state information The fields z_stream::zalloc, z_stream::zfree and z_stream::opaque must be initialized before by the caller.
levelcompression level.

If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default allocation functions. total_in, total_out, adler, and msg are initialized.

The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION requests a default compromise between speed and compression (currently equivalent to level 6).

deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if level is not a valid compression level, or Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible with the version assumed by the caller (ZLIB_VERSION).

Note
msg is set to null if there is no error message. deflateInit() does not perform any compression; this will be done by deflate().

◆ gzoffset()

z_off_t ZEXPORT gzoffset ( gzFile  file)

Return the current compressed (actual) read or write offset of file.

This offset includes the count of bytes that precede the gzip stream, for example when appending or when using gzdopen() for reading. When reading, the offset does not include as yet unused buffered input. This information can be used for a progress indicator. On error, gzoffset() returns -1.

◆ gzopen()

gzFile ZEXPORT gzopen ( const char *  path,
const char *  mode 
)

Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing.

The mode parameter is as in fopen ("rb" or "wb") but can also include a compression level ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression as in "wb9F". (See the description of deflateInit2 for more information about the strategy parameter.) 'T' will request transparent writing or appending with no compression and not using the gzip format.

"a" can be used instead of "w" to request that the gzip stream that will be written be appended to the file. "+" will result in an error, since reading and writing to the same gzip file is not supported. The addition of "x" when writing will create the file exclusively, which fails if the file already exists. On systems that support it, the addition of "e" when reading or writing will set the flag to close the file on an execve() call.

These functions, as well as gzip, will read and decode a sequence of gzip streams in a file. The append function of gzopen() can be used to create such a file. (Also see gzflush() for another way to do this.) When appending, gzopen does not test whether the file begins with a gzip stream, nor does it look for the end of the gzip streams to begin appending. gzopen will simply append a gzip stream to the existing file.

gzopen can be used to read a file which is not in gzip format; in this case gzread will directly read from the file without decompression. When reading, this will be detected automatically by looking for the magic two- byte gzip header.

Returns
NULL if the file could not be opened, if there was insufficient memory to allocate the gzFile state, or if an invalid mode was specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). errno can be checked to determine if the reason gzopen failed was that the file could not be opened.

◆ gzseek()

z_off_t ZEXPORT gzseek ( gzFile  file,
z_off_t  offset,
int  whence 
)

Set the starting position to offset relative to whence for the next gzread or gzwrite on file.

The offset represents a number of bytes in the uncompressed data stream. The whence parameter is defined as in lseek(2); the value SEEK_END is not supported.

If the file is opened for reading, this function is emulated but can be extremely slow. If the file is opened for writing, only forward seeks are supported; gzseek then compresses a sequence of zeroes up to the new starting position.

gzseek returns the resulting offset location as measured in bytes from the beginning of the uncompressed stream, or -1 in case of error, in particular if the file is opened for writing and the new starting position would be before the current position.

◆ gztell()

z_off_t ZEXPORT gztell ( gzFile  file)

Return the starting position for the next gzread or gzwrite on file.

This position represents a number of bytes in the uncompressed data stream, and is zero when starting, even if appending or reading a gzip stream from the middle of a file using gzdopen().

gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)

◆ inflateBackInit_()

int ZEXPORT inflateBackInit_ ( z_streamp  strm,
int  windowBits,
unsigned char *  window,
const char *  version,
int  stream_size 
)

Initialize the internal stream state for decompression using inflateBack() calls.

The fields zalloc, zfree and opaque in strm must be initialized before the call. If zalloc and zfree are Z_NULL, then the default library- derived memory allocation routines are used. windowBits is the base two logarithm of the window size, in the range 8..15. window is a caller supplied buffer of that size. Except for special applications where it is assured that deflate was used with small window sizes, windowBits must be 15 and a 32K byte window must be supplied to be able to decompress general deflate streams.

See inflateBack() for the usage of these routines.

Returns
Z_OK on success
Z_STREAM_ERROR if any of the parameters are invalid
Z_MEM_ERROR if the internal state could not be allocated
Z_VERSION_ERROR if the version of the library does not match the version of the header file.

◆ inflateInit2_()

int ZEXPORT inflateInit2_ ( z_streamp  strm,
int  windowBits,
const char *  version,
int  stream_size 
)

This is another version of inflateInit with an extra parameter.

The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller.

The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. The default value is 15 if inflateInit is used instead. windowBits must be greater than or equal to the windowBits value provided to deflateInit2() while compressing, or it must be equal to 15 if deflateInit2() was not used. If a compressed stream with a larger window size is given as input, inflate() will return with the error code Z_DATA_ERROR instead of trying to allocate a larger window.

windowBits can also be zero to request that inflate use the window size in the zlib header of the compressed stream.

windowBits can also be -8..-15 for raw inflate. In this case, -windowBits determines the window size. inflate() will then process raw deflate data, not looking for a zlib or gzip header, not generating a check value, and not looking for any check values for comparison at the end of the stream. This is for use with other formats that use the deflate compressed data format such as zip. Those formats provide their own check values. If a custom format is developed using the raw deflate format for compressed data, it is recommended that a check value such as an Adler-32 or a CRC-32 be applied to the uncompressed data as is done in the zlib, gzip, and zip formats. For most applications, the zlib format should be used as is. Note that comments above on the use in deflateInit2() applies to the magnitude of windowBits.

windowBits can also be greater than 15 for optional gzip decoding. Add 32 to windowBits to enable zlib and gzip decoding with automatic header detection, or add 16 to decode only the gzip format (the zlib format will return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see below), inflate() will not automatically decode concatenated gzip members. inflate() will return Z_STREAM_END at the end of the gzip member. The state would need to be reset to continue decoding a subsequent gzip member. This must* be done if there is more data after a gzip member, in order for the decompression to be compliant with the gzip standard (RFC 1952).

inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the version assumed by the caller, or Z_STREAM_ERROR if the parameters are invalid, such as a null pointer to the structure. msg is set to null if there is no error message. inflateInit2 does not perform any decompression apart from possibly reading the zlib header if present: actual decompression will be done by inflate(). (So next_in and avail_in may be modified, but next_out and avail_out are unused and unchanged.) The current implementation of inflateInit2() does not process any header information – that is deferred until inflate() is called.

◆ inflateInit_()

int ZEXPORT inflateInit_ ( z_streamp  strm,
const char *  version,
int  stream_size 
)

Initializes the internal stream state for decompression.

The fields z_stream_s::next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller. In the current version of inflate, the provided input is not read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates them to use default allocation functions. total_in, total_out, adler, and msg are initialized.

inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the version assumed by the caller, or Z_STREAM_ERROR if the parameters are invalid, such as a null pointer to the structure. msg is set to null if there is no error message. inflateInit does not perform any decompression. Actual decompression will be done by inflate(). So next_in, and avail_in, next_out, and avail_out are unused and unchanged. The current implementation of inflateInit() does not process any header information – that is deferred until inflate() is called.