111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* zlib.h -- interface of the 'zlib' general purpose compression library 211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert version 1.2.3, July 18th, 2005 311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler 511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This software is provided 'as-is', without any express or implied 711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert warranty. In no event will the authors be held liable for any damages 811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert arising from the use of this software. 911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Permission is granted to anyone to use this software for any purpose, 1111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert including commercial applications, and to alter it and redistribute it 1211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert freely, subject to the following restrictions: 1311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1. The origin of this software must not be misrepresented; you must not 1511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert claim that you wrote the original software. If you use this software 1611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert in a product, an acknowledgment in the product documentation would be 1711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert appreciated but is not required. 1811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2. Altered source versions must be plainly marked as such, and must not be 1911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert misrepresented as being the original software. 2011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3. This notice may not be removed or altered from any source distribution. 2111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Jean-loup Gailly Mark Adler 2311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert jloup@gzip.org madler@alumni.caltech.edu 2411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The data format used by the zlib library is described by RFCs (Request for 2711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt 2811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 2911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 3011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifndef ZLIB_H 3211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define ZLIB_H 3311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include "zconf.h" 3511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifdef __cplusplus 3711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertextern "C" { 3811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif 3911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define ZLIB_VERSION "1.2.3" 4111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define ZLIB_VERNUM 0x1230 4211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 4411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The 'zlib' compression library provides in-memory compression and 4511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert decompression functions, including integrity checks of the uncompressed 4611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert data. This version of the library supports only one compression method 4711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (deflation) but other algorithms will be added later and will have the same 4811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream interface. 4911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Compression can be done in a single step if the buffers are large 5111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough (for example if an input file is mmap'ed), or can be done by 5211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert repeated calls of the compression function. In the latter case, the 5311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert application must provide more input and/or consume the output 5411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (providing more output space) before each call. 5511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The compressed data format used by default by the in-memory functions is 5711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 5811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert around a deflate stream, which is itself documented in RFC 1951. 5911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The library also supports reading and writing files in gzip (.gz) format 6111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert with an interface similar to that of stdio using the functions that start 6211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert with "gz". The gzip format is different from the zlib format. gzip is a 6311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 6411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This library can optionally read and write gzip streams in memory as well. 6611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The zlib format was designed to be compact and fast for use in memory 6811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and on communications channels. The gzip format was designed for single- 6911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert file compression on file systems, has a larger header than zlib to maintain 7011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert directory information, and uses a different, slower check method than zlib. 7111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 7211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The library does not install any signal handler. The decoder checks 7311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the consistency of the compressed data, so the library should never 7411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert crash even in case of corrupted input. 7511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 7611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 7711cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 7811cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef void (*free_func) OF((voidpf opaque, voidpf address)); 7911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertstruct internal_state; 8111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8211cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct z_stream_s { 8311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Bytef *next_in; /* next input byte */ 8411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt avail_in; /* number of bytes available at next_in */ 8511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong total_in; /* total nb of input bytes read so far */ 8611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Bytef *next_out; /* next output byte should be put there */ 8811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt avail_out; /* remaining free space at next_out */ 8911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong total_out; /* total nb of bytes output so far */ 9011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert char *msg; /* last error message, NULL if no error */ 9211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert struct internal_state FAR *state; /* not visible by applications */ 9311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert alloc_func zalloc; /* used to allocate the internal state */ 9511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert free_func zfree; /* used to free the internal state */ 9611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert voidpf opaque; /* private data object passed to zalloc and zfree */ 9711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int data_type; /* best guess about the data type: binary or text */ 9911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong adler; /* adler32 value of the uncompressed data */ 10011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong reserved; /* reserved for future use */ 10111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} z_stream; 10211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10311cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef z_stream FAR *z_streamp; 10411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 10611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzip header information passed to and from zlib routines. See RFC 1952 10711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert for more details on the meanings of these fields. 10811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 10911cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct gz_header_s { 11011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int text; /* true if compressed data believed to be text */ 11111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong time; /* modification time */ 11211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int xflags; /* extra flags (not used when writing a gzip file) */ 11311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int os; /* operating system */ 11411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Bytef *extra; /* pointer to extra field or Z_NULL if none */ 11511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 11611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt extra_max; /* space at extra (only when reading header) */ 11711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 11811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt name_max; /* space at name (only when reading header) */ 11911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 12011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt comm_max; /* space at comment (only when reading header) */ 12111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int hcrc; /* true if there was or will be a header crc */ 12211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int done; /* true when done reading gzip header (not used 12311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert when writing a gzip file) */ 12411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} gz_header; 12511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12611cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef gz_header FAR *gz_headerp; 12711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 12911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The application must update next_in and avail_in when avail_in has 13011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert dropped to zero. It must update next_out and avail_out when avail_out 13111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert has dropped to zero. The application must initialize zalloc, zfree and 13211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert opaque before calling the init function. All other fields are set by the 13311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression library and must not be updated by the application. 13411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 13511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The opaque value provided by the application will be passed as the first 13611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert parameter for calls of zalloc and zfree. This can be useful for custom 13711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert memory management. The compression library attaches no meaning to the 13811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert opaque value. 13911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert zalloc must return Z_NULL if there is not enough memory for the object. 14111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If zlib is used in a multi-threaded application, zalloc and zfree must be 14211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert thread safe. 14311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert On 16-bit systems, the functions zalloc and zfree must be able to allocate 14511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert exactly 65536 bytes, but will not be required to allocate more than this 14611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 14711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pointers returned by zalloc for objects of exactly 65536 bytes *must* 14811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert have their offset normalized to zero. The default allocation function 14911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert provided by this library ensures this (see zutil.c). To reduce memory 15011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert requirements and avoid any allocation of 64K objects, at the expense of 15111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 15211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 15311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The fields total_in and total_out can be used for statistics or 15411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert progress reports. After compression, total_in holds the total size of 15511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the uncompressed data and may be saved for use in the decompressor 15611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (particularly if the decompressor wants to decompress everything in 15711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert a single step). 15811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 15911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 16011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert /* constants */ 16111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 16211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_NO_FLUSH 0 16311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 16411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_SYNC_FLUSH 2 16511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_FULL_FLUSH 3 16611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_FINISH 4 16711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_BLOCK 5 16811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Allowed flush values; see deflate() and inflate() below for details */ 16911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 17011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_OK 0 17111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_STREAM_END 1 17211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_NEED_DICT 2 17311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_ERRNO (-1) 17411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_STREAM_ERROR (-2) 17511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_DATA_ERROR (-3) 17611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_MEM_ERROR (-4) 17711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_BUF_ERROR (-5) 17811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_VERSION_ERROR (-6) 17911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Return codes for the compression/decompression functions. Negative 18011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * values are errors, positive values are used for special but normal events. 18111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 18211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 18311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_NO_COMPRESSION 0 18411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_BEST_SPEED 1 18511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_BEST_COMPRESSION 9 18611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_DEFAULT_COMPRESSION (-1) 18711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* compression levels */ 18811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 18911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_FILTERED 1 19011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_HUFFMAN_ONLY 2 19111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_RLE 3 19211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_FIXED 4 19311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_DEFAULT_STRATEGY 0 19411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* compression strategy; see deflateInit2() below for details */ 19511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 19611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_BINARY 0 19711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_TEXT 1 19811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 19911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_UNKNOWN 2 20011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Possible values of the data_type field (though see inflate()) */ 20111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 20211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_DEFLATED 8 20311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* The deflate compression method (the only one supported in this version) */ 20411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 20511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 20611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 20711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define zlib_version zlibVersion() 20811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* for compatibility with versions < 1.0.2 */ 20911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert /* basic functions */ 21111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21211cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN const char * ZEXPORT zlibVersion OF((void)); 21311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 21411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If the first character differs, the library code actually used is 21511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert not compatible with the zlib.h header file used by the application. 21611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This check is automatically made by deflateInit and inflateInit. 21711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 21811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 22011cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 22111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 22211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Initializes the internal stream state for compression. The fields 22311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert zalloc, zfree and opaque must be initialized before by the caller. 22411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If zalloc and zfree are set to Z_NULL, deflateInit updates them to 22511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert use default allocation functions. 22611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 22711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 22811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1 gives best speed, 9 gives best compression, 0 gives no compression at 22911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert all (the input data is simply copied a block at a time). 23011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_DEFAULT_COMPRESSION requests a default compromise between speed and 23111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression (currently equivalent to level 6). 23211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 23311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 23411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough memory, Z_STREAM_ERROR if level is not a valid compression level, 23511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 23611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert with the version assumed by the caller (ZLIB_VERSION). 23711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert msg is set to null if there is no error message. deflateInit does not 23811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert perform any compression: this will be done by deflate(). 23911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 24011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 24111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 24211cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 24311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 24411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate compresses as much data as possible, and stops when the input 24511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert buffer becomes empty or the output buffer becomes full. It may introduce some 24611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert output latency (reading input without producing any output) except when 24711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert forced to flush. 24811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 24911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The detailed semantics are as follows. deflate performs one or both of the 25011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert following actions: 25111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 25211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert - Compress more input starting at next_in and update next_in and avail_in 25311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert accordingly. If not all input can be processed (because there is not 25411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough room in the output buffer), next_in and avail_in are updated and 25511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert processing will resume at this point for the next call of deflate(). 25611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 25711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert - Provide more output starting at next_out and update next_out and avail_out 25811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert accordingly. This action is forced if the parameter flush is non zero. 25911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Forcing flush frequently degrades the compression ratio, so this parameter 26011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert should be set only when necessary (in interactive applications). 26111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Some output may be provided even if flush is not set. 26211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 26311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Before the call of deflate(), the application should ensure that at least 26411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert one of the actions is possible, by providing more input and/or consuming 26511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert more output, and updating avail_in or avail_out accordingly; avail_out 26611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert should never be zero before the call. The application can consume the 26711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressed output when it wants, for example when the output buffer is full 26811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 26911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and with zero avail_out, it must be called again after making room in the 27011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert output buffer because there might be more output pending. 27111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 27311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert decide how much data to accumualte before producing output, in order to 27411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert maximize compression. 27511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 27711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert flushed to the output buffer and the output is aligned on a byte boundary, so 27811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert that the decompressor can get all input data available so far. (In particular 27911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert avail_in is zero after the call if enough output space has been provided 28011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert before the call.) Flushing may degrade compression for some compression 28111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert algorithms and so it should be used only when necessary. 28211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 28311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If flush is set to Z_FULL_FLUSH, all output is flushed as with 28411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_SYNC_FLUSH, and the compression state is reset so that decompression can 28511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert restart from this point if previous compressed data has been damaged or if 28611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 28711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression. 28811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 28911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If deflate returns with avail_out == 0, this function must be called again 29011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert with the same value of the flush parameter and more output space (updated 29111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert avail_out), until the flush is complete (deflate returns with non-zero 29211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 29311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert avail_out is greater than six to avoid repeated flush markers due to 29411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert avail_out == 0 on return. 29511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 29611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If the parameter flush is set to Z_FINISH, pending input is processed, 29711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pending output is flushed and deflate returns with Z_STREAM_END if there 29811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert was enough output space; if deflate returns with Z_OK, this function must be 29911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert called again with Z_FINISH and more output space (updated avail_out) but no 30011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert more input data, until it returns with Z_STREAM_END or an error. After 30111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate has returned Z_STREAM_END, the only possible operations on the 30211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream are deflateReset or deflateEnd. 30311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 30411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_FINISH can be used immediately after deflateInit if all the compression 30511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is to be done in a single step. In this case, avail_out must be at least 30611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the value returned by deflateBound (see below). If deflate does not return 30711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_STREAM_END, then it must be called again as described above. 30811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 30911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate() sets strm->adler to the adler32 checksum of all input read 31011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert so far (that is, total_in bytes). 31111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 31211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate() may update strm->data_type if it can make a good guess about 31311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 31411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert binary. This field is only for information purposes and does not affect 31511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the compression algorithm in any manner. 31611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 31711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate() returns Z_OK if some progress has been made (more input 31811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert processed or more output produced), Z_STREAM_END if all input has been 31911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert consumed and all output has been produced (only when flush is set to 32011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 32111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 32211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 32311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert fatal, and deflate() can be called again with more input and more output 32411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert space to continue compressing. 32511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 32611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 32711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 32811cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 32911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 33011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert All dynamically allocated data structures for this stream are freed. 33111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function discards any unprocessed input and does not flush any 33211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pending output. 33311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 33411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 33511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent, Z_DATA_ERROR if the stream was freed 33611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert prematurely (some input or output was discarded). In the error case, 33711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert msg may be set but then points to a static string (which must not be 33811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deallocated). 33911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 34011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 34111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 34211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 34311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 34411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 34511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Initializes the internal stream state for decompression. The fields 34611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert next_in, avail_in, zalloc, zfree and opaque must be initialized before by 34711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 34811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert value depends on the compression method), inflateInit determines the 34911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression method from the zlib header and allocates all data structures 35011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert accordingly; otherwise the allocation will be deferred to the first call of 35111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 35211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert use default allocation functions. 35311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 35411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 35511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 35611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert version assumed by the caller. msg is set to null if there is no error 35711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert message. inflateInit does not perform any decompression apart from reading 35811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the zlib header if present: this will be done by inflate(). (So next_in and 35911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert avail_in may be modified, but next_out and avail_out are unchanged.) 36011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 36111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 36211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 36311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 36411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 36511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate decompresses as much data as possible, and stops when the input 36611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert buffer becomes empty or the output buffer becomes full. It may introduce 36711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert some output latency (reading input without producing any output) except when 36811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert forced to flush. 36911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 37011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The detailed semantics are as follows. inflate performs one or both of the 37111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert following actions: 37211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 37311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert - Decompress more input starting at next_in and update next_in and avail_in 37411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert accordingly. If not all input can be processed (because there is not 37511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough room in the output buffer), next_in is updated and processing 37611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert will resume at this point for the next call of inflate(). 37711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 37811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert - Provide more output starting at next_out and update next_out and avail_out 37911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert accordingly. inflate() provides as much output as possible, until there 38011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is no more input data or no more space in the output buffer (see below 38111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert about the flush parameter). 38211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 38311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Before the call of inflate(), the application should ensure that at least 38411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert one of the actions is possible, by providing more input and/or consuming 38511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert more output, and updating the next_* and avail_* values accordingly. 38611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The application can consume the uncompressed output when it wants, for 38711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert example when the output buffer is full (avail_out == 0), or after each 38811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert call of inflate(). If inflate returns Z_OK and with zero avail_out, it 38911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert must be called again after making room in the output buffer because there 39011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert might be more output pending. 39111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 39211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, 39311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much 39411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert output as possible to the output buffer. Z_BLOCK requests that inflate() stop 39511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if and when it gets to the next deflate block boundary. When decoding the 39611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert zlib or gzip format, this will cause inflate() to return immediately after 39711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the header and before the first block. When doing a raw inflate, inflate() 39811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert will go ahead and process the first block, and will return when it gets to 39911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the end of that block, or when it runs out of data. 40011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 40111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The Z_BLOCK option assists in appending to or combining deflate streams. 40211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Also to assist in this, on return inflate() will set strm->data_type to the 40311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert number of unused bits in the last byte taken from strm->next_in, plus 64 40411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if inflate() is currently decoding the last block in the deflate stream, 40511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert plus 128 if inflate() returned immediately after decoding an end-of-block 40611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert code or decoding the complete header up to just before the first byte of the 40711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate stream. The end-of-block will not be indicated until all of the 40811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed data from that block has been written to strm->next_out. The 40911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert number of unused bits may in general be greater than seven, except when 41011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert bit 7 of data_type is set, in which case the number of unused bits will be 41111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert less than eight. 41211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 41311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate() should normally be called until it returns Z_STREAM_END or an 41411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert error. However if all decompression is to be performed in a single step 41511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (a single call of inflate), the parameter flush should be set to 41611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_FINISH. In this case all pending input is processed and all pending 41711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert output is flushed; avail_out must be large enough to hold all the 41811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed data. (The size of the uncompressed data may have been saved 41911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert by the compressor for this purpose.) The next operation on this stream must 42011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert be inflateEnd to deallocate the decompression state. The use of Z_FINISH 42111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is never required, but can be used to inform inflate that a faster approach 42211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert may be used for the single inflate() call. 42311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 42411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert In this implementation, inflate() always flushes as much output as 42511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert possible to the output buffer, and always uses the faster approach on the 42611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert first call. So the only effect of the flush parameter in this implementation 42711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is on the return value of inflate(), as noted below, or when it returns early 42811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert because Z_BLOCK is used. 42911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 43011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If a preset dictionary is needed after this call (see inflateSetDictionary 43111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert below), inflate sets strm->adler to the adler32 checksum of the dictionary 43211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 43311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert strm->adler to the adler32 checksum of all output produced so far (that is, 43411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 43511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert below. At the end of the stream, inflate() checks that its computed adler32 43611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert checksum is equal to that saved by the compressor and returns Z_STREAM_END 43711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert only if the checksum is correct. 43811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 43911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate() will decompress and check either zlib-wrapped or gzip-wrapped 44011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate data. The header type is detected automatically. Any information 44111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert contained in the gzip header is not retained, so applications that need that 44211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert information should instead use raw inflate, see inflateInit2() below, or 44311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBack() and perform their own processing of the gzip header and 44411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert trailer. 44511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 44611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate() returns Z_OK if some progress has been made (more input processed 44711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert or more output produced), Z_STREAM_END if the end of the compressed data has 44811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert been reached and all uncompressed output has been produced, Z_NEED_DICT if a 44911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 45011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert corrupted (input stream not conforming to the zlib format or incorrect check 45111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 45211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, 45311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_BUF_ERROR if no progress is possible or if there was not enough room in the 45411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 45511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate() can be called again with more input and more output space to 45611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert continue decompressing. If Z_DATA_ERROR is returned, the application may then 45711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert call inflateSync() to look for a good compression block if a partial recovery 45811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert of the data is desired. 45911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 46011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 46111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 46211cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 46311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 46411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert All dynamically allocated data structures for this stream are freed. 46511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function discards any unprocessed input and does not flush any 46611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pending output. 46711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 46811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 46911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert was inconsistent. In the error case, msg may be set but then points to a 47011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert static string (which must not be deallocated). 47111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 47211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 47311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert /* Advanced functions */ 47411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 47511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 47611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The following functions are needed only in some special applications. 47711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 47811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 47911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 48011cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 48111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int level, 48211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int method, 48311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int windowBits, 48411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int memLevel, 48511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int strategy)); 48611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 48711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This is another version of deflateInit with more compression options. The 48811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert fields next_in, zalloc, zfree and opaque must be initialized before by 48911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the caller. 49011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 49111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The method parameter is the compression method. It must be Z_DEFLATED in 49211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert this version of the library. 49311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 49411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The windowBits parameter is the base two logarithm of the window size 49511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (the size of the history buffer). It should be in the range 8..15 for this 49611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert version of the library. Larger values of this parameter result in better 49711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression at the expense of memory usage. The default value is 15 if 49811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit is used instead. 49911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 50011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 50111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert determines the window size. deflate() will then generate raw deflate data 50211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert with no zlib header or trailer, and will not compute an adler32 check value. 50311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 50411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert windowBits can also be greater than 15 for optional gzip encoding. Add 50511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 16 to windowBits to write a simple gzip header and trailer around the 50611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressed data instead of a zlib wrapper. The gzip header will have no 50711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert file name, no extra data, no comment, no modification time (set to zero), 50811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert no header crc, and the operating system will be set to 255 (unknown). If a 50911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzip stream is being written, strm->adler is a crc32 instead of an adler32. 51011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 51111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The memLevel parameter specifies how much memory should be allocated 51211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert for the internal compression state. memLevel=1 uses minimum memory but 51311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is slow and reduces compression ratio; memLevel=9 uses maximum memory 51411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert for optimal speed. The default value is 8. See zconf.h for total memory 51511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert usage as a function of windowBits and memLevel. 51611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 51711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The strategy parameter is used to tune the compression algorithm. Use the 51811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 51911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 52011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert string match), or Z_RLE to limit match distances to one (run-length 52111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert encoding). Filtered data consists mostly of small values with a somewhat 52211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert random distribution. In this case, the compression algorithm is tuned to 52311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compress them better. The effect of Z_FILTERED is to force more Huffman 52411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert coding and less string matching; it is somewhat intermediate between 52511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as 52611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy 52711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert parameter only affects the compression ratio but not the correctness of the 52811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressed output even if it is not set appropriately. Z_FIXED prevents the 52911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert use of dynamic Huffman codes, allowing for a simpler decoder for special 53011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert applications. 53111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 53211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 53311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 53411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert method). msg is set to null if there is no error message. deflateInit2 does 53511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert not perform any compression: this will be done by deflate(). 53611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 53711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 53811cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 53911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const Bytef *dictionary, 54011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt dictLength)); 54111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 54211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Initializes the compression dictionary from the given byte sequence 54311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert without producing any compressed output. This function must be called 54411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert immediately after deflateInit, deflateInit2 or deflateReset, before any 54511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert call of deflate. The compressor and decompressor must use exactly the same 54611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert dictionary (see inflateSetDictionary). 54711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 54811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The dictionary should consist of strings (byte sequences) that are likely 54911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert to be encountered later in the data to be compressed, with the most commonly 55011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert used strings preferably put towards the end of the dictionary. Using a 55111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert dictionary is most useful when the data to be compressed is short and can be 55211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert predicted with good accuracy; the data can then be compressed better than 55311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert with the default empty dictionary. 55411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 55511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Depending on the size of the compression data structures selected by 55611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit or deflateInit2, a part of the dictionary may in effect be 55711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert discarded, for example if the dictionary is larger than the window size in 55811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate or deflate2. Thus the strings most likely to be useful should be 55911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert put at the end of the dictionary, not at the front. In addition, the 56011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert current implementation of deflate will use at most the window size minus 56111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 262 bytes of the provided dictionary. 56211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 56311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Upon return of this function, strm->adler is set to the adler32 value 56411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert of the dictionary; the decompressor may later use this value to determine 56511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert which dictionary has been used by the compressor. (The adler32 value 56611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert applies to the whole dictionary even if only a subset of the dictionary is 56711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert actually used by the compressor.) If a raw deflate was requested, then the 56811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert adler32 value is not computed and strm->adler is not set. 56911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 57011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 57111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert parameter is invalid (such as NULL dictionary) or the stream state is 57211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inconsistent (for example if deflate has already been called for this stream 57311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert or if the compression method is bsort). deflateSetDictionary does not 57411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert perform any compression: this will be done by deflate(). 57511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 57611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 57711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 57811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert z_streamp source)); 57911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 58011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Sets the destination stream as a complete copy of the source stream. 58111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 58211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function can be useful when several compression strategies will be 58311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert tried, for example when there are several ways of pre-processing the input 58411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert data with a filter. The streams that will be discarded should then be freed 58511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert by calling deflateEnd. Note that deflateCopy duplicates the internal 58611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression state which can be quite large, so this strategy is slow and 58711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert can consume lots of memory. 58811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 58911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 59011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 59111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (such as zalloc being NULL). msg is left unchanged in both source and 59211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert destination. 59311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 59411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 59511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 59611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 59711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function is equivalent to deflateEnd followed by deflateInit, 59811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert but does not free and reallocate all the internal compression state. 59911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The stream will keep the same compression level and any other attributes 60011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert that may have been set by deflateInit2. 60111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 60211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 60311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent (such as zalloc or state being NULL). 60411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 60511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 60611cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 60711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int level, 60811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int strategy)); 60911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 61011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Dynamically update the compression level and compression strategy. The 61111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert interpretation of level and strategy is as in deflateInit2. This can be 61211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert used to switch between compression and straight copy of the input data, or 61311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert to switch to a different kind of input data requiring a different 61411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert strategy. If the compression level is changed, the input available so far 61511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is compressed with the old level (and may be flushed); the new level will 61611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert take effect only at the next call of deflate(). 61711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 61811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Before the call of deflateParams, the stream state must be set as for 61911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert a call of deflate(), since the currently available input may have to 62011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert be compressed and flushed. In particular, strm->avail_out must be non-zero. 62111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 62211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 62311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 62411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if strm->avail_out was zero. 62511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 62611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 62711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 62811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int good_length, 62911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int max_lazy, 63011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int nice_length, 63111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int max_chain)); 63211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 63311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Fine tune deflate's internal compression parameters. This should only be 63411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert used by someone who understands the algorithm used by zlib's deflate for 63511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert searching for the best matching string, and even then only by the most 63611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert fanatic optimizer trying to squeeze out the last compressed bit for their 63711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert specific input data. Read the deflate.c source code for the meaning of the 63811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert max_lazy, good_length, nice_length, and max_chain parameters. 63911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 64011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateTune() can be called after deflateInit() or deflateInit2(), and 64111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 64211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 64311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 64411cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 64511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong sourceLen)); 64611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 64711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateBound() returns an upper bound on the compressed size after 64811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflation of sourceLen bytes. It must be called after deflateInit() 64911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert or deflateInit2(). This would be used to allocate an output buffer 65011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert for deflation in a single pass, and so would be called before deflate(). 65111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 65211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 65311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 65411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int bits, 65511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int value)); 65611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 65711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflatePrime() inserts bits in the deflate output stream. The intent 65811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is that this function is used to start off the deflate output with the 65911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert bits leftover from a previous deflate stream when appending to it. As such, 66011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert this function can only be used for raw deflate, and must be used before the 66111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert first deflate() call after a deflateInit2() or deflateReset(). bits must be 66211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert less than or equal to 16, and that many of the least significant bits of 66311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert value will be inserted in the output. 66411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 66511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 66611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent. 66711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 66811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 66911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 67011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gz_headerp head)); 67111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 67211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateSetHeader() provides gzip header information for when a gzip 67311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream is requested by deflateInit2(). deflateSetHeader() may be called 67411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert after deflateInit2() or deflateReset() and before the first call of 67511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate(). The text, time, os, extra field, name, and comment information 67611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert in the provided gz_header structure are written to the gzip header (xflag is 67711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ignored -- the extra flags are set according to the compression level). The 67811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert caller must assure that, if not Z_NULL, name and comment are terminated with 67911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 68011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert available there. If hcrc is true, a gzip header crc is included. Note that 68111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the current versions of the command-line version of gzip (up through version 68211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1.3.x) do not support header crc's, and will report that it is a "multi-part 68311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzip file" and give up. 68411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 68511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If deflateSetHeader is not used, the default gzip header has text false, 68611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the time set to zero, and os set to 255, with no extra, name, or comment 68711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert fields. The gzip header is returned to the default state by deflateReset(). 68811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 68911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 69011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent. 69111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 69211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 69311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 69411cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 69511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int windowBits)); 69611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 69711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This is another version of inflateInit with an extra parameter. The 69811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert fields next_in, avail_in, zalloc, zfree and opaque must be initialized 69911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert before by the caller. 70011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 70111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The windowBits parameter is the base two logarithm of the maximum window 70211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert size (the size of the history buffer). It should be in the range 8..15 for 70311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert this version of the library. The default value is 15 if inflateInit is used 70411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert instead. windowBits must be greater than or equal to the windowBits value 70511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert provided to deflateInit2() while compressing, or it must be equal to 15 if 70611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit2() was not used. If a compressed stream with a larger window 70711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert size is given as input, inflate() will return with the error code 70811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_DATA_ERROR instead of trying to allocate a larger window. 70911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 71011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 71111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert determines the window size. inflate() will then process raw deflate data, 71211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert not looking for a zlib or gzip header, not generating a check value, and not 71311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert looking for any check values for comparison at the end of the stream. This 71411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is for use with other formats that use the deflate compressed data format 71511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert such as zip. Those formats provide their own check values. If a custom 71611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert format is developed using the raw deflate format for compressed data, it is 71711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert recommended that a check value such as an adler32 or a crc32 be applied to 71811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the uncompressed data as is done in the zlib, gzip, and zip formats. For 71911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert most applications, the zlib format should be used as is. Note that comments 72011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert above on the use in deflateInit2() applies to the magnitude of windowBits. 72111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 72211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert windowBits can also be greater than 15 for optional gzip decoding. Add 72311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 32 to windowBits to enable zlib and gzip decoding with automatic header 72411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert detection, or add 16 to decode only the gzip format (the zlib format will 72511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 72611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert a crc32 instead of an adler32. 72711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 72811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 72911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg 73011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is set to null if there is no error message. inflateInit2 does not perform 73111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert any decompression apart from reading the zlib header if present: this will 73211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert be done by inflate(). (So next_in and avail_in may be modified, but next_out 73311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and avail_out are unchanged.) 73411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 73511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 73611cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 73711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const Bytef *dictionary, 73811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uInt dictLength)); 73911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 74011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Initializes the decompression dictionary from the given uncompressed byte 74111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert sequence. This function must be called immediately after a call of inflate, 74211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 74311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert can be determined from the adler32 value returned by that call of inflate. 74411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The compressor and decompressor must use exactly the same dictionary (see 74511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateSetDictionary). For raw inflate, this function can be called 74611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert immediately after inflateInit2() or inflateReset() and before any call of 74711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate() to set the dictionary. The application must insure that the 74811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert dictionary that was used for compression is provided. 74911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 75011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 75111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert parameter is invalid (such as NULL dictionary) or the stream state is 75211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 75311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert expected one (incorrect adler32 value). inflateSetDictionary does not 75411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert perform any decompression: this will be done by subsequent calls of 75511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflate(). 75611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 75711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 75811cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 75911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 76011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Skips invalid compressed data until a full flush point (see above the 76111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert description of deflate with Z_FULL_FLUSH) can be found, or until all 76211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert available input is skipped. No output is provided. 76311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 76411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 76511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if no more input was provided, Z_DATA_ERROR if no flush point has been found, 76611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 76711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert case, the application may save the current current value of total_in which 76811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert indicates where valid compressed data was found. In the error case, the 76911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert application may repeatedly call inflateSync, providing more input each time, 77011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert until success or end of the input data. 77111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 77211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 77311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 77411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert z_streamp source)); 77511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 77611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Sets the destination stream as a complete copy of the source stream. 77711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 77811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function can be useful when randomly accessing a large stream. The 77911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert first pass through the stream can periodically record the inflate state, 78011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert allowing restarting inflate at those points when randomly accessing the 78111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream. 78211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 78311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 78411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 78511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (such as zalloc being NULL). msg is left unchanged in both source and 78611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert destination. 78711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 78811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 78911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 79011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 79111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function is equivalent to inflateEnd followed by inflateInit, 79211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert but does not free and reallocate all the internal decompression state. 79311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The stream will keep attributes that may have been set by inflateInit2. 79411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 79511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 79611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent (such as zalloc or state being NULL). 79711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 79811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 79911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 80011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int bits, 80111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int value)); 80211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 80311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function inserts bits in the inflate input stream. The intent is 80411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert that this function is used to start inflating at a bit position in the 80511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert middle of a byte. The provided bits will be used before any bytes are used 80611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert from next_in. This function should only be used with raw inflate, and 80711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert should be used before the first inflate() call after inflateInit2() or 80811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateReset(). bits must be less than or equal to 16, and that many of the 80911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert least significant bits of value will be inserted in the input. 81011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 81111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 81211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent. 81311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 81411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 81511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 81611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gz_headerp head)); 81711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 81811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateGetHeader() requests that gzip header information be stored in the 81911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert provided gz_header structure. inflateGetHeader() may be called after 82011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateInit2() or inflateReset(), and before the first call of inflate(). 82111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert As inflate() processes the gzip stream, head->done is zero until the header 82211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is completed, at which time head->done is set to one. If a zlib stream is 82311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert being decoded, then head->done is set to -1 to indicate that there will be 82411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert no gzip header information forthcoming. Note that Z_BLOCK can be used to 82511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert force inflate() to return immediately after header processing is complete 82611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and before any actual data is decompressed. 82711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 82811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The text, time, xflags, and os fields are filled in with the gzip header 82911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert contents. hcrc is set to true if there is a header CRC. (The header CRC 83011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert was valid if done is set to one.) If extra is not Z_NULL, then extra_max 83111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert contains the maximum number of bytes to write to extra. Once done is true, 83211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert extra_len contains the actual extra field length, and extra contains the 83311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert extra field, or that field truncated if extra_max is less than extra_len. 83411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If name is not Z_NULL, then up to name_max characters are written there, 83511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert terminated with a zero unless the length is greater than name_max. If 83611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert comment is not Z_NULL, then up to comm_max characters are written there, 83711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert terminated with a zero unless the length is greater than comm_max. When 83811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert any of extra, name, or comment are not Z_NULL and the respective field is 83911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert not present in the header, then that field is set to Z_NULL to signal its 84011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert absence. This allows the use of deflateSetHeader() with the returned 84111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert structure to duplicate the header. However if those fields are set to 84211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert allocated memory, then the application will need to save those pointers 84311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert elsewhere so that they can be eventually freed. 84411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 84511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If inflateGetHeader is not used, then the header information is simply 84611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert discarded. The header is always checked for validity, including the header 84711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert CRC if present. inflateReset() will reset the process to discard the header 84811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert information. The application would need to call inflateGetHeader() again to 84911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert retrieve the header from the next gzip stream. 85011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 85111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 85211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert stream state was inconsistent. 85311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 85411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 85511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 85611cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 85711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert unsigned char FAR *window)); 85811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 85911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Initialize the internal stream state for decompression using inflateBack() 86011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert calls. The fields zalloc, zfree and opaque in strm must be initialized 86111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert before the call. If zalloc and zfree are Z_NULL, then the default library- 86211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert derived memory allocation routines are used. windowBits is the base two 86311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert logarithm of the window size, in the range 8..15. window is a caller 86411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert supplied buffer of that size. Except for special applications where it is 86511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert assured that deflate was used with small window sizes, windowBits must be 15 86611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and a 32K byte window must be supplied to be able to decompress general 86711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate streams. 86811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 86911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert See inflateBack() for the usage of these routines. 87011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 87111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 87211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the paramaters are invalid, Z_MEM_ERROR if the internal state could not 87311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert be allocated, or Z_VERSION_ERROR if the version of the library does not 87411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert match the version of the header file. 87511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 87611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 87711cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 87811cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 87911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 88011cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 88111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert in_func in, void FAR *in_desc, 88211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert out_func out, void FAR *out_desc)); 88311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 88411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBack() does a raw inflate with a single call using a call-back 88511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert interface for input and output. This is more efficient than inflate() for 88611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert file i/o applications in that it avoids copying between the output and the 88711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert sliding window by simply making the window itself the output buffer. This 88811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert function trusts the application to not change the output buffer passed by 88911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the output function, at least until inflateBack() returns. 89011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 89111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBackInit() must be called first to allocate the internal state 89211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and to initialize the state with the user-provided window buffer. 89311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBack() may then be used multiple times to inflate a complete, raw 89411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate stream with each call. inflateBackEnd() is then called to free 89511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the allocated state. 89611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 89711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert A raw deflate stream is one with no zlib or gzip header or trailer. 89811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This routine would normally be used in a utility that reads zip or gzip 89911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert files and writes out uncompressed files. The utility would decode the 90011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert header and process the trailer on its own, hence this routine expects 90111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert only the raw deflate stream to decompress. This is different from the 90211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert normal behavior of inflate(), which expects either a zlib or gzip header and 90311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert trailer around the deflate stream. 90411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 90511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBack() uses two subroutines supplied by the caller that are then 90611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert called by inflateBack() for input and output. inflateBack() calls those 90711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert routines until it reads a complete deflate stream and writes out all of the 90811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed data, or until it encounters an error. The function's 90911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert parameters and return types are defined above in the in_func and out_func 91011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert typedefs. inflateBack() will call in(in_desc, &buf) which should return the 91111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert number of bytes of provided input, and a pointer to that input in buf. If 91211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert there is no input available, in() must return zero--buf is ignored in that 91311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert case--and inflateBack() will return a buffer error. inflateBack() will call 91411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 91511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert should return zero on success, or non-zero on failure. If out() returns 91611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert non-zero, inflateBack() will return with an error. Neither in() nor out() 91711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert are permitted to change the contents of the window provided to 91811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBackInit(), which is also the buffer that out() uses to write from. 91911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The length written by out() will be at most the window size. Any non-zero 92011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert amount of input may be provided by in(). 92111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 92211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert For convenience, inflateBack() can be provided input on the first call by 92311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert setting strm->next_in and strm->avail_in. If that input is exhausted, then 92411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert in() will be called. Therefore strm->next_in must be initialized before 92511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 92611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 92711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert must also be initialized, and then if strm->avail_in is not zero, input will 92811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 92911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 93011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The in_desc and out_desc parameters of inflateBack() is passed as the 93111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert first parameter of in() and out() respectively when they are called. These 93211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert descriptors can be optionally used to pass any information that the caller- 93311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert supplied in() and out() functions need to do their job. 93411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 93511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert On return, inflateBack() will set strm->next_in and strm->avail_in to 93611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pass back any unused input that was provided by the last in() call. The 93711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 93811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if in() or out() returned an error, Z_DATA_ERROR if there was a format 93911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert error in the deflate stream (in which case strm->msg is set to indicate the 94011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert nature of the error), or Z_STREAM_ERROR if the stream was not properly 94111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert initialized. In the case of Z_BUF_ERROR, an input or output error can be 94211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert distinguished using strm->next_in which will be Z_NULL only if in() returned 94311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to 94411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert out() returning non-zero. (in() will always be called before out(), so 94511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert strm->next_in is assured to be defined if out() returns non-zero.) Note 94611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert that inflateBack() cannot return Z_OK. 94711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 94811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 94911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 95011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 95111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert All memory allocated by inflateBackInit() is freed. 95211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 95311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 95411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert state was inconsistent. 95511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 95611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 95711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 95811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Return flags indicating compile-time options. 95911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 96011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 96111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1.0: size of uInt 96211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3.2: size of uLong 96311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5.4: size of voidpf (pointer) 96411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 7.6: size of z_off_t 96511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 96611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Compiler, assembler, and debug options: 96711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8: DEBUG 96811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9: ASMV or ASMINF -- use ASM code 96911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 97011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 11: 0 (reserved) 97111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 97211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert One-time table building (smaller code, but not thread-safe if true): 97311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12: BUILDFIXED -- build static block decoding tables when needed 97411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 97511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14,15: 0 (reserved) 97611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 97711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Library content (indicates missing functionality): 97811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 97911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflate code when not needed) 98011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 98111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and decode gzip streams (to avoid linking crc code) 98211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 18-19: 0 (reserved) 98311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 98411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Operation variations (changes in library functionality): 98511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 98611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21: FASTEST -- deflate algorithm with only one, lowest compression level 98711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 22,23: 0 (reserved) 98811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 98911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The sprintf variant used by gzprintf (zero is best): 99011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 99111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 99211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 99311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 99411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Remainder: 99511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27-31: 0 (reserved) 99611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 99711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 99811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 99911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert /* utility functions */ 100011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 100111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 100211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The following utility functions are implemented on top of the 100311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert basic stream-oriented functions. To simplify the interface, some 100411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert default options are assumed (compression level and memory usage, 100511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert standard memory allocation functions). The source code of these 100611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert utility functions can easily be modified if you need special options. 100711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 100811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 100911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 101011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const Bytef *source, uLong sourceLen)); 101111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 101211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Compresses the source buffer into the destination buffer. sourceLen is 101311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the byte length of the source buffer. Upon entry, destLen is the total 101411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert size of the destination buffer, which must be at least the value returned 101511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert by compressBound(sourceLen). Upon exit, destLen is the actual size of the 101611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressed buffer. 101711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function can be used to compress a whole file at once if the 101811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert input file is mmap'ed. 101911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compress returns Z_OK if success, Z_MEM_ERROR if there was not 102011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough memory, Z_BUF_ERROR if there was not enough room in the output 102111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert buffer. 102211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 102311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 102411cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 102511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const Bytef *source, uLong sourceLen, 102611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int level)); 102711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 102811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Compresses the source buffer into the destination buffer. The level 102911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert parameter has the same meaning as in deflateInit. sourceLen is the byte 103011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert length of the source buffer. Upon entry, destLen is the total size of the 103111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert destination buffer, which must be at least the value returned by 103211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressBound(sourceLen). Upon exit, destLen is the actual size of the 103311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressed buffer. 103411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 103511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 103611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert memory, Z_BUF_ERROR if there was not enough room in the output buffer, 103711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Z_STREAM_ERROR if the level parameter is invalid. 103811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 103911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 104011cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 104111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 104211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compressBound() returns an upper bound on the compressed size after 104311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compress() or compress2() on sourceLen bytes. It would be used before 104411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert a compress() or compress2() call to allocate the destination buffer. 104511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 104611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 104711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 104811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const Bytef *source, uLong sourceLen)); 104911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 105011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Decompresses the source buffer into the destination buffer. sourceLen is 105111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the byte length of the source buffer. Upon entry, destLen is the total 105211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert size of the destination buffer, which must be large enough to hold the 105311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert entire uncompressed data. (The size of the uncompressed data must have 105411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert been saved previously by the compressor and transmitted to the decompressor 105511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert by some mechanism outside the scope of this compression library.) 105611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Upon exit, destLen is the actual size of the compressed buffer. 105711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert This function can be used to decompress a whole file at once if the 105811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert input file is mmap'ed. 105911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 106011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 106111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert enough memory, Z_BUF_ERROR if there was not enough room in the output 106211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. 106311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 106411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 106511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 106611cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef voidp gzFile; 106711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 106811cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 106911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 107011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Opens a gzip (.gz) file for reading or writing. The mode parameter 107111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert is as in fopen ("rb" or "wb") but can also include a compression level 107211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 107311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Huffman only compression as in "wb1h", or 'R' for run-length encoding 107411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert as in "wb1R". (See the description of deflateInit2 for more information 107511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert about the strategy parameter.) 107611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 107711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzopen can be used to read a file which is not in gzip format; in this 107811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert case gzread will directly read from the file without decompression. 107911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 108011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzopen returns NULL if the file could not be opened or if there was 108111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert insufficient memory to allocate the (de)compression state; errno 108211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert can be checked to distinguish the two cases (if errno is zero, the 108311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert zlib error is Z_MEM_ERROR). */ 108411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 108511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 108611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 108711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzdopen() associates a gzFile with the file descriptor fd. File 108811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert descriptors are obtained from calls like open, dup, creat, pipe or 108911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert fileno (in the file has been previously opened with fopen). 109011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The mode parameter is as in gzopen. 109111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert The next call of gzclose on the returned gzFile will also close the 109211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 109311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 109411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzdopen returns NULL if there was insufficient memory to allocate 109511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the (de)compression state. 109611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 109711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 109811cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 109911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 110011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Dynamically update the compression level or strategy. See the description 110111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert of deflateInit2 for the meaning of these parameters. 110211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 110311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert opened for writing. 110411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 110511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 110611cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 110711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 110811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Reads the given number of uncompressed bytes from the compressed file. 110911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If the input file was not in gzip format, gzread copies the given number 111011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert of bytes into the buffer. 111111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzread returns the number of uncompressed bytes actually read (0 for 111211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert end of file, -1 for error). */ 111311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 111411cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzwrite OF((gzFile file, 111511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert voidpc buf, unsigned len)); 111611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 111711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Writes the given number of uncompressed bytes into the compressed file. 111811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzwrite returns the number of uncompressed bytes actually written 111911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (0 in case of error). 112011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 112111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 112211cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 112311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 112411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Converts, formats, and writes the args to the compressed file under 112511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert control of the format string, as in fprintf. gzprintf returns the number of 112611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed bytes actually written (0 in case of error). The number of 112711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed bytes written is limited to 4095. The caller should assure that 112811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert this limit is not exceeded. If it is exceeded, then gzprintf() will return 112911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return an error (0) with nothing written. In this case, there may also be a 113011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert buffer overflow with unpredictable consequences, which is possible only if 113111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert zlib was compiled with the insecure functions sprintf() or vsprintf() 113211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert because the secure snprintf() or vsnprintf() functions were not available. 113311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 113411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 113511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 113611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 113711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Writes the given null-terminated string to the compressed file, excluding 113811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the terminating null character. 113911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzputs returns the number of characters written, or -1 in case of error. 114011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 114111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 114211cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 114311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 114411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Reads bytes from the compressed file until len-1 characters are read, or 114511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert a newline character is read and transferred to buf, or an end-of-file 114611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert condition is encountered. The string is then terminated with a null 114711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert character. 114811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzgets returns buf, or Z_NULL in case of error. 114911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 115011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 115111cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 115211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 115311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Writes c, converted to an unsigned char, into the compressed file. 115411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzputc returns the value that was written, or -1 in case of error. 115511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 115611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 115711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 115811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 115911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Reads one byte from the compressed file. gzgetc returns this byte 116011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert or -1 in case of end of file or error. 116111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 116211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 116311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 116411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 116511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Push one character back onto the stream to be read again later. 116611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Only one character of push-back is allowed. gzungetc() returns the 116711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert character pushed, or -1 on failure. gzungetc() will fail if a 116811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert character has been pushed but not read yet, or if c is -1. The pushed 116911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert character will be discarded if the stream is repositioned with gzseek() 117011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert or gzrewind(). 117111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 117211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 117311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 117411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 117511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Flushes all pending output into the compressed file. The parameter 117611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert flush is as in the deflate() function. The return value is the zlib 117711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert error number (see function gzerror below). gzflush returns Z_OK if 117811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the flush parameter is Z_FINISH and all output could be flushed. 117911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzflush should be called only when strictly necessary because it can 118011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert degrade compression. 118111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 118211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 118311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 118411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert z_off_t offset, int whence)); 118511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 118611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Sets the starting position for the next gzread or gzwrite on the 118711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert given compressed file. The offset represents a number of bytes in the 118811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed data stream. The whence parameter is defined as in lseek(2); 118911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the value SEEK_END is not supported. 119011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert If the file is opened for reading, this function is emulated but can be 119111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert extremely slow. If the file is opened for writing, only forward seeks are 119211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert supported; gzseek then compresses a sequence of zeroes up to the new 119311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert starting position. 119411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 119511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzseek returns the resulting offset location as measured in bytes from 119611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the beginning of the uncompressed stream, or -1 in case of error, in 119711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert particular if the file is opened for writing and the new starting position 119811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert would be before the current position. 119911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 120011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 120111cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 120211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 120311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Rewinds the given file. This function is supported only for reading. 120411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 120511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 120611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 120711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 120811cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 120911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 121011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Returns the starting position for the next gzread or gzwrite on the 121111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert given compressed file. This position represents a number of bytes in the 121211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uncompressed data stream. 121311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 121411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 121511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 121611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 121711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzeof OF((gzFile file)); 121811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 121911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Returns 1 when EOF has previously been detected reading the given 122011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert input stream, otherwise zero. 122111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 122211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 122311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 122411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 122511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Returns 1 if file is being read directly without decompression, otherwise 122611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert zero. 122711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 122811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 122911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT gzclose OF((gzFile file)); 123011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 123111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Flushes all pending output if necessary, closes the compressed file 123211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and deallocates all the (de)compression state. The return value is the zlib 123311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert error number (see function gzerror below). 123411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 123511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 123611cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 123711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 123811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Returns the error message for the last error which occurred on the 123911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert given compressed file. errnum is set to zlib error number. If an 124011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert error occurred in the file system and not in the compression library, 124111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert errnum is set to Z_ERRNO and the application may consult errno 124211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert to get the exact error code. 124311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 124411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 124511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 124611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 124711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Clears the error and end-of-file flags for file. This is analogous to the 124811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert clearerr() function in stdio. This is useful for continuing to read a gzip 124911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert file that is being written concurrently. 125011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 125111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 125211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert /* checksum functions */ 125311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 125411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 125511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert These functions are not related to compression but are exported 125611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert anyway because they might be useful in applications using the 125711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert compression library. 125811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 125911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 126011cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 126111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 126211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Update a running Adler-32 checksum with the bytes buf[0..len-1] and 126311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return the updated checksum. If buf is NULL, this function returns 126411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert the required initial value for the checksum. 126511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 126611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert much faster. Usage example: 126711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 126811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong adler = adler32(0L, Z_NULL, 0); 126911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 127011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert while (read_buffer(buffer, length) != EOF) { 127111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert adler = adler32(adler, buffer, length); 127211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert } 127311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (adler != original_adler) error(); 127411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 127511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 127611cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 127711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert z_off_t len2)); 127811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 127911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 128011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 128111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 128211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. 128311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 128411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 128511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 128611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 128711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Update a running CRC-32 with the bytes buf[0..len-1] and return the 128811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert updated CRC-32. If buf is NULL, this function returns the required initial 128911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert value for the for the crc. Pre- and post-conditioning (one's complement) is 129011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert performed within this function so it shouldn't be done by the application. 129111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Usage example: 129211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 129311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uLong crc = crc32(0L, Z_NULL, 0); 129411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 129511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert while (read_buffer(buffer, length) != EOF) { 129611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert crc = crc32(crc, buffer, length); 129711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert } 129811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (crc != original_crc) error(); 129911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 130011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 130111cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 130211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 130311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 130411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert Combine two CRC-32 check values into one. For two sequences of bytes, 130511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 130611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 130711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 130811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert len2. 130911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert*/ 131011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 131111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 131211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert /* various hacks, don't look :) */ 131311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 131411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* deflateInit and inflateInit are macros to allow checking the zlib version 131511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * and the compiler's view of z_stream: 131611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 131711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 131811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const char *version, int stream_size)); 131911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 132011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const char *version, int stream_size)); 132111cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 132211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int windowBits, int memLevel, 132311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int strategy, const char *version, 132411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int stream_size)); 132511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 132611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const char *version, int stream_size)); 132711cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 132811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert unsigned char FAR *window, 132911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const char *version, 133011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int stream_size)); 133111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define deflateInit(strm, level) \ 133211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 133311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define inflateInit(strm) \ 133411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 133511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 133611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 133711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert (strategy), ZLIB_VERSION, sizeof(z_stream)) 133811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define inflateInit2(strm, windowBits) \ 133911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 134011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define inflateBackInit(strm, windowBits, window) \ 134111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert inflateBackInit_((strm), (windowBits), (window), \ 134211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ZLIB_VERSION, sizeof(z_stream)) 134311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 134411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 134511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) 134611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert struct internal_state {int dummy;}; /* hack for buggy compilers */ 134711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif 134811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 134911cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN const char * ZEXPORT zError OF((int)); 135011cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); 135111cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); 135211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 135311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifdef __cplusplus 135411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 135511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif 135611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 135711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif /* ZLIB_H */ 1358