zlib.h revision 168404
162587Sitojun/* zlib.h -- interface of the 'zlib' general purpose compression library 295023Ssuz version 1.2.3, July 18th, 2005 362587Sitojun 4139826Simp Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler 553541Sshin 653541Sshin This software is provided 'as-is', without any express or implied 753541Sshin warranty. In no event will the authors be held liable for any damages 853541Sshin arising from the use of this software. 953541Sshin 1053541Sshin Permission is granted to anyone to use this software for any purpose, 1153541Sshin including commercial applications, and to alter it and redistribute it 1253541Sshin freely, subject to the following restrictions: 1353541Sshin 1453541Sshin 1. The origin of this software must not be misrepresented; you must not 1553541Sshin claim that you wrote the original software. If you use this software 1653541Sshin in a product, an acknowledgment in the product documentation would be 1753541Sshin appreciated but is not required. 1853541Sshin 2. Altered source versions must be plainly marked as such, and must not be 1953541Sshin misrepresented as being the original software. 2053541Sshin 3. This notice may not be removed or altered from any source distribution. 2153541Sshin 2253541Sshin Jean-loup Gailly Mark Adler 2353541Sshin jloup@gzip.org madler@alumni.caltech.edu 2453541Sshin 2553541Sshin 2653541Sshin The data format used by the zlib library is described by RFCs (Request for 2753541Sshin Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt 2853541Sshin (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 2953541Sshin*/ 3053541Sshin 3153541Sshin#ifndef _ZLIB_H 3253541Sshin#define _ZLIB_H 3362587Sitojun 3462587Sitojun#pragma ident "%Z%%M% %I% %E% SMI" 35142215Sglebius 36142215Sglebius#include "zconf.h" 3755009Sshin 3853541Sshin#ifdef __cplusplus 3953541Sshinextern "C" { 4053541Sshin#endif 4153541Sshin 4253541Sshin#define ZLIB_VERSION "1.2.3" 4353541Sshin#define ZLIB_VERNUM 0x1230 4453541Sshin 4553541Sshin/* 4653541Sshin The 'zlib' compression library provides in-memory compression and 4753541Sshin decompression functions, including integrity checks of the uncompressed 4853541Sshin data. This version of the library supports only one compression method 4978064Sume (deflation) but other algorithms will be added later and will have the same 5053541Sshin stream interface. 5153541Sshin 5253541Sshin Compression can be done in a single step if the buffers are large 5353541Sshin enough (for example if an input file is mmap'ed), or can be done by 54147306Sbrooks repeated calls of the compression function. In the latter case, the 5553541Sshin application must provide more input and/or consume the output 5653541Sshin (providing more output space) before each call. 5753541Sshin 5853541Sshin The compressed data format used by default by the in-memory functions is 5953541Sshin the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 6062587Sitojun around a deflate stream, which is itself documented in RFC 1951. 6153541Sshin 62148385Sume The library also supports reading and writing files in gzip (.gz) format 6353541Sshin with an interface similar to that of stdio using the functions that start 6462587Sitojun with "gz". The gzip format is different from the zlib format. gzip is a 6553541Sshin gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 66142215Sglebius 67142215Sglebius This library can optionally read and write gzip streams in memory as well. 68142215Sglebius 69142215Sglebius The zlib format was designed to be compact and fast for use in memory 7053541Sshin and on communications channels. The gzip format was designed for single- 7153541Sshin file compression on file systems, has a larger header than zlib to maintain 7262587Sitojun directory information, and uses a different, slower check method than zlib. 7353541Sshin 7462587Sitojun The library does not install any signal handler. The decoder checks 7562587Sitojun the consistency of the compressed data, so the library should never 7678064Sume crash even in case of corrupted input. 7778064Sume*/ 7862587Sitojun 7962587Sitojuntypedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 8062587Sitojuntypedef void (*free_func) OF((voidpf opaque, voidpf address)); 8162587Sitojun 8253541Sshinstruct internal_state; 8362587Sitojun 8462587Sitojuntypedef struct z_stream_s { 8553541Sshin Bytef *next_in; /* next input byte */ 8653541Sshin uInt avail_in; /* number of bytes available at next_in */ 87108470Sschweikh uLong total_in; /* total nb of input bytes read so far */ 8853541Sshin 8953541Sshin Bytef *next_out; /* next output byte should be put there */ 90148987Sume uInt avail_out; /* remaining free space at next_out */ 9153541Sshin uLong total_out; /* total nb of bytes output so far */ 9253541Sshin 9353541Sshin char *msg; /* last error message, NULL if no error */ 9453541Sshin struct internal_state FAR *state; /* not visible by applications */ 9553541Sshin 9653541Sshin alloc_func zalloc; /* used to allocate the internal state */ 9753541Sshin free_func zfree; /* used to free the internal state */ 9853541Sshin voidpf opaque; /* private data object passed to zalloc and zfree */ 9962587Sitojun 10053541Sshin int data_type; /* best guess about the data type: binary or text */ 10153541Sshin uLong adler; /* adler32 value of the uncompressed data */ 10262587Sitojun uLong reserved; /* reserved for future use */ 10353541Sshin} z_stream; 10453541Sshin 105142215Sglebiustypedef z_stream FAR *z_streamp; 10653541Sshin 10753541Sshin/* 10853541Sshin gzip header information passed to and from zlib routines. See RFC 1952 10953541Sshin for more details on the meanings of these fields. 11062587Sitojun*/ 11153541Sshintypedef struct gz_header_s { 11278064Sume int text; /* true if compressed data believed to be text */ 11378064Sume uLong time; /* modification time */ 11478064Sume int xflags; /* extra flags (not used when writing a gzip file) */ 11578064Sume int os; /* operating system */ 11678064Sume Bytef *extra; /* pointer to extra field or Z_NULL if none */ 11778064Sume uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 11878064Sume uInt extra_max; /* space at extra (only when reading header) */ 11978064Sume Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 12078064Sume uInt name_max; /* space at name (only when reading header) */ 12178064Sume Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 12278064Sume uInt comm_max; /* space at comment (only when reading header) */ 12378064Sume int hcrc; /* true if there was or will be a header crc */ 124148385Sume int done; /* true when done reading gzip header (not used 125148385Sume when writing a gzip file) */ 12678064Sume} gz_header; 12753541Sshin 12878064Sumetypedef gz_header FAR *gz_headerp; 12978064Sume 13078064Sume/* 13178064Sume The application must update next_in and avail_in when avail_in has 13278064Sume dropped to zero. It must update next_out and avail_out when avail_out 13353541Sshin has dropped to zero. The application must initialize zalloc, zfree and 13453541Sshin opaque before calling the init function. All other fields are set by the 13553541Sshin compression library and must not be updated by the application. 136148987Sume 137120941Sume The opaque value provided by the application will be passed as the first 13895023Ssuz parameter for calls of zalloc and zfree. This can be useful for custom 139120941Sume memory management. The compression library attaches no meaning to the 140120941Sume opaque value. 141120941Sume 14295023Ssuz zalloc must return Z_NULL if there is not enough memory for the object. 14353541Sshin If zlib is used in a multi-threaded application, zalloc and zfree must be 14478064Sume thread safe. 145120941Sume 14653541Sshin On 16-bit systems, the functions zalloc and zfree must be able to allocate 14753541Sshin exactly 65536 bytes, but will not be required to allocate more than this 14853541Sshin if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 14953541Sshin pointers returned by zalloc for objects of exactly 65536 bytes *must* 15053541Sshin have their offset normalized to zero. The default allocation function 15178064Sume provided by this library ensures this (see zutil.c). To reduce memory 15253541Sshin requirements and avoid any allocation of 64K objects, at the expense of 15353541Sshin compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 15453541Sshin 15553541Sshin The fields total_in and total_out can be used for statistics or 15653541Sshin progress reports. After compression, total_in holds the total size of 15753541Sshin the uncompressed data and may be saved for use in the decompressor 15878064Sume (particularly if the decompressor wants to decompress everything in 15978064Sume a single step). 16078064Sume*/ 16178064Sume 16253541Sshin /* constants */ 16353541Sshin 16453541Sshin#define Z_NO_FLUSH 0 16595023Ssuz#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 16653541Sshin#define Z_SYNC_FLUSH 2 16753541Sshin#define Z_FULL_FLUSH 3 168120941Sume#define Z_FINISH 4 16953541Sshin#define Z_BLOCK 5 17078064Sume/* Allowed flush values; see deflate() and inflate() below for details */ 17178064Sume 17253541Sshin#define Z_OK 0 17353541Sshin#define Z_STREAM_END 1 17453541Sshin#define Z_NEED_DICT 2 17553541Sshin#define Z_ERRNO (-1) 17653541Sshin#define Z_STREAM_ERROR (-2) 17753541Sshin#define Z_DATA_ERROR (-3) 17853541Sshin#define Z_MEM_ERROR (-4) 17953541Sshin#define Z_BUF_ERROR (-5) 18053541Sshin#define Z_VERSION_ERROR (-6) 18153541Sshin/* Return codes for the compression/decompression functions. Negative 18253541Sshin * values are errors, positive values are used for special but normal events. 18353541Sshin */ 18453541Sshin 18562587Sitojun#define Z_NO_COMPRESSION 0 18662587Sitojun#define Z_BEST_SPEED 1 18762587Sitojun#define Z_BEST_COMPRESSION 9 18862587Sitojun#define Z_DEFAULT_COMPRESSION (-1) 18962587Sitojun/* compression levels */ 19062587Sitojun 19153541Sshin#define Z_FILTERED 1 19253541Sshin#define Z_HUFFMAN_ONLY 2 19353541Sshin#define Z_RLE 3 19453541Sshin#define Z_FIXED 4 19553541Sshin#define Z_DEFAULT_STRATEGY 0 19653541Sshin/* compression strategy; see deflateInit2() below for details */ 19753541Sshin 19853541Sshin#define Z_BINARY 0 19953541Sshin#define Z_TEXT 1 20053541Sshin#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 20153541Sshin#define Z_UNKNOWN 2 20253541Sshin/* Possible values of the data_type field (though see inflate()) */ 203142215Sglebius 204142215Sglebius#define Z_DEFLATED 8 205142215Sglebius/* The deflate compression method (the only one supported in this version) */ 206151465Ssuz 207142215Sglebius#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 208142215Sglebius 20953541Sshin#define zlib_version zlibVersion() 210142215Sglebius/* for compatibility with versions < 1.0.2 */ 21153541Sshin 21253541Sshin /* basic functions */ 213151465Ssuz 21453541SshinZEXTERN const char * ZEXPORT zlibVersion OF((void)); 21553541Sshin/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 216121765Ssam If the first character differs, the library code actually used is 21753541Sshin not compatible with the zlib.h header file used by the application. 21853541Sshin This check is automatically made by deflateInit and inflateInit. 21953541Sshin */ 22053541Sshin 22153541Sshin/* 22253541SshinZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 22353541Sshin 224121765Ssam Initializes the internal stream state for compression. The fields 225121765Ssam zalloc, zfree and opaque must be initialized before by the caller. 226121765Ssam If zalloc and zfree are set to Z_NULL, deflateInit updates them to 227121765Ssam use default allocation functions. 228121765Ssam 22953541Sshin The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 23062587Sitojun 1 gives best speed, 9 gives best compression, 0 gives no compression at 23153541Sshin all (the input data is simply copied a block at a time). 23262587Sitojun Z_DEFAULT_COMPRESSION requests a default compromise between speed and 23362587Sitojun compression (currently equivalent to level 6). 23462587Sitojun 23553541Sshin deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 23662587Sitojun enough memory, Z_STREAM_ERROR if level is not a valid compression level, 23762587Sitojun Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 23853541Sshin with the version assumed by the caller (ZLIB_VERSION). 23953541Sshin msg is set to null if there is no error message. deflateInit does not 24053541Sshin perform any compression: this will be done by deflate(). 24153541Sshin*/ 24278064Sume 24353541Sshin 24453541SshinZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 24553541Sshin/* 24662587Sitojun deflate compresses as much data as possible, and stops when the input 24753541Sshin buffer becomes empty or the output buffer becomes full. It may introduce some 24853541Sshin output latency (reading input without producing any output) except when 24953541Sshin forced to flush. 25053541Sshin 25153541Sshin The detailed semantics are as follows. deflate performs one or both of the 25262587Sitojun following actions: 25353541Sshin 25453541Sshin - Compress more input starting at next_in and update next_in and avail_in 255120941Sume accordingly. If not all input can be processed (because there is not 25653541Sshin enough room in the output buffer), next_in and avail_in are updated and 257120941Sume processing will resume at this point for the next call of deflate(). 258120941Sume 25978064Sume - Provide more output starting at next_out and update next_out and avail_out 26053541Sshin accordingly. This action is forced if the parameter flush is non zero. 26153541Sshin Forcing flush frequently degrades the compression ratio, so this parameter 26253541Sshin should be set only when necessary (in interactive applications). 263120941Sume Some output may be provided even if flush is not set. 264120941Sume 26562587Sitojun Before the call of deflate(), the application should ensure that at least 26653541Sshin one of the actions is possible, by providing more input and/or consuming 26753541Sshin more output, and updating avail_in or avail_out accordingly; avail_out 26853541Sshin should never be zero before the call. The application can consume the 26953541Sshin compressed output when it wants, for example when the output buffer is full 27053541Sshin (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 27153541Sshin and with zero avail_out, it must be called again after making room in the 27253541Sshin output buffer because there might be more output pending. 27353541Sshin 27453541Sshin Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 27553541Sshin decide how much data to accumualte before producing output, in order to 27653541Sshin maximize compression. 27753541Sshin 27853541Sshin If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 27953541Sshin flushed to the output buffer and the output is aligned on a byte boundary, so 28053541Sshin that the decompressor can get all input data available so far. (In particular 28153541Sshin avail_in is zero after the call if enough output space has been provided 28253541Sshin before the call.) Flushing may degrade compression for some compression 283148987Sume algorithms and so it should be used only when necessary. 28453541Sshin 28553541Sshin If flush is set to Z_FULL_FLUSH, all output is flushed as with 28653541Sshin Z_SYNC_FLUSH, and the compression state is reset so that decompression can 28753541Sshin restart from this point if previous compressed data has been damaged or if 28853541Sshin random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 28953541Sshin compression. 29053541Sshin 29162587Sitojun If deflate returns with avail_out == 0, this function must be called again 29253541Sshin with the same value of the flush parameter and more output space (updated 29353541Sshin avail_out), until the flush is complete (deflate returns with non-zero 29453541Sshin avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 29553541Sshin avail_out is greater than six to avoid repeated flush markers due to 29653541Sshin avail_out == 0 on return. 29753541Sshin 29853541Sshin If the parameter flush is set to Z_FINISH, pending input is processed, 29953541Sshin pending output is flushed and deflate returns with Z_STREAM_END if there 30053541Sshin was enough output space; if deflate returns with Z_OK, this function must be 30153541Sshin called again with Z_FINISH and more output space (updated avail_out) but no 30253541Sshin more input data, until it returns with Z_STREAM_END or an error. After 303148385Sume deflate has returned Z_STREAM_END, the only possible operations on the 304148385Sume stream are deflateReset or deflateEnd. 305148385Sume 306148385Sume Z_FINISH can be used immediately after deflateInit if all the compression 307148385Sume is to be done in a single step. In this case, avail_out must be at least 308148385Sume the value returned by deflateBound (see below). If deflate does not return 309120941Sume Z_STREAM_END, then it must be called again as described above. 310120941Sume 311120941Sume deflate() sets strm->adler to the adler32 checksum of all input read 31262587Sitojun so far (that is, total_in bytes). 31353541Sshin 31453541Sshin deflate() may update strm->data_type if it can make a good guess about 315120941Sume the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 316120941Sume binary. This field is only for information purposes and does not affect 31753541Sshin the compression algorithm in any manner. 31853541Sshin 319120941Sume deflate() returns Z_OK if some progress has been made (more input 320120941Sume processed or more output produced), Z_STREAM_END if all input has been 321120941Sume consumed and all output has been produced (only when flush is set to 32262587Sitojun Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 32362587Sitojun if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 32453541Sshin (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 32553541Sshin fatal, and deflate() can be called again with more input and more output 32653541Sshin space to continue compressing. 32778064Sume*/ 32878064Sume 32978064Sume 33078064SumeZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 33162587Sitojun/* 33253541Sshin All dynamically allocated data structures for this stream are freed. 33353541Sshin This function discards any unprocessed input and does not flush any 33453541Sshin pending output. 335108470Sschweikh 33653541Sshin deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 33753541Sshin stream state was inconsistent, Z_DATA_ERROR if the stream was freed 33853541Sshin prematurely (some input or output was discarded). In the error case, 33953541Sshin msg may be set but then points to a static string (which must not be 34053541Sshin deallocated). 341148987Sume*/ 34253541Sshin 34353541Sshin 34453541Sshin/* 34553541SshinZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 34678064Sume 34753541Sshin Initializes the internal stream state for decompression. The fields 348148987Sume next_in, avail_in, zalloc, zfree and opaque must be initialized before by 34953541Sshin the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 35053541Sshin value depends on the compression method), inflateInit determines the 35153541Sshin compression method from the zlib header and allocates all data structures 35253541Sshin accordingly; otherwise the allocation will be deferred to the first call of 353148385Sume inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 35453541Sshin use default allocation functions. 35553541Sshin 35662587Sitojun inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 35753541Sshin memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 358148385Sume version assumed by the caller. msg is set to null if there is no error 359120941Sume message. inflateInit does not perform any decompression apart from reading 360148385Sume the zlib header if present: this will be done by inflate(). (So next_in and 361148385Sume avail_in may be modified, but next_out and avail_out are unchanged.) 36253541Sshin*/ 36353541Sshin 36453541Sshin 36562587SitojunZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 36662587Sitojun/* 36762587Sitojun inflate decompresses as much data as possible, and stops when the input 36862587Sitojun buffer becomes empty or the output buffer becomes full. It may introduce 36962587Sitojun some output latency (reading input without producing any output) except when 37062587Sitojun forced to flush. 37162587Sitojun 37262587Sitojun The detailed semantics are as follows. inflate performs one or both of the 37353541Sshin following actions: 37462587Sitojun 37553541Sshin - Decompress more input starting at next_in and update next_in and avail_in 376111119Simp accordingly. If not all input can be processed (because there is not 37762587Sitojun enough room in the output buffer), next_in is updated and processing 378111119Simp will resume at this point for the next call of inflate(). 37962587Sitojun 38062587Sitojun - Provide more output starting at next_out and update next_out and avail_out 38162587Sitojun accordingly. inflate() provides as much output as possible, until there 38262587Sitojun is no more input data or no more space in the output buffer (see below 38362587Sitojun about the flush parameter). 38462587Sitojun 38562587Sitojun Before the call of inflate(), the application should ensure that at least 38678064Sume one of the actions is possible, by providing more input and/or consuming 38762587Sitojun more output, and updating the next_* and avail_* values accordingly. 38853541Sshin The application can consume the uncompressed output when it wants, for 38953541Sshin example when the output buffer is full (avail_out == 0), or after each 39053541Sshin call of inflate(). If inflate returns Z_OK and with zero avail_out, it 39153541Sshin must be called again after making room in the output buffer because there 39253541Sshin might be more output pending. 39353541Sshin 39453541Sshin The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, 39553541Sshin Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much 39653541Sshin output as possible to the output buffer. Z_BLOCK requests that inflate() stop 39795023Ssuz if and when it gets to the next deflate block boundary. When decoding the 39853541Sshin zlib or gzip format, this will cause inflate() to return immediately after 39953541Sshin the header and before the first block. When doing a raw inflate, inflate() 40053541Sshin will go ahead and process the first block, and will return when it gets to 40153541Sshin the end of that block, or when it runs out of data. 40262587Sitojun 40362587Sitojun The Z_BLOCK option assists in appending to or combining deflate streams. 40453541Sshin Also to assist in this, on return inflate() will set strm->data_type to the 40553541Sshin number of unused bits in the last byte taken from strm->next_in, plus 64 40653541Sshin if inflate() is currently decoding the last block in the deflate stream, 40753541Sshin plus 128 if inflate() returned immediately after decoding an end-of-block 40853541Sshin code or decoding the complete header up to just before the first byte of the 40953541Sshin deflate stream. The end-of-block will not be indicated until all of the 41053541Sshin uncompressed data from that block has been written to strm->next_out. The 411148385Sume number of unused bits may in general be greater than seven, except when 41253541Sshin bit 7 of data_type is set, in which case the number of unused bits will be 41353541Sshin less than eight. 41453541Sshin 41553541Sshin inflate() should normally be called until it returns Z_STREAM_END or an 416148385Sume error. However if all decompression is to be performed in a single step 417148385Sume (a single call of inflate), the parameter flush should be set to 41853541Sshin Z_FINISH. In this case all pending input is processed and all pending 41953541Sshin output is flushed; avail_out must be large enough to hold all the 42053541Sshin uncompressed data. (The size of the uncompressed data may have been saved 42153541Sshin by the compressor for this purpose.) The next operation on this stream must 42253541Sshin be inflateEnd to deallocate the decompression state. The use of Z_FINISH 42353541Sshin is never required, but can be used to inform inflate that a faster approach 42453541Sshin may be used for the single inflate() call. 42553541Sshin 42653541Sshin In this implementation, inflate() always flushes as much output as 42753541Sshin possible to the output buffer, and always uses the faster approach on the 42853541Sshin first call. So the only effect of the flush parameter in this implementation 42953541Sshin is on the return value of inflate(), as noted below, or when it returns early 43053541Sshin because Z_BLOCK is used. 43153541Sshin 43253541Sshin If a preset dictionary is needed after this call (see inflateSetDictionary 433148385Sume below), inflate sets strm->adler to the adler32 checksum of the dictionary 43453541Sshin chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 43595023Ssuz strm->adler to the adler32 checksum of all output produced so far (that is, 436148385Sume total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 43753541Sshin below. At the end of the stream, inflate() checks that its computed adler32 43853541Sshin checksum is equal to that saved by the compressor and returns Z_STREAM_END 439148987Sume only if the checksum is correct. 440148987Sume 441148987Sume inflate() will decompress and check either zlib-wrapped or gzip-wrapped 442148987Sume deflate data. The header type is detected automatically. Any information 44353541Sshin contained in the gzip header is not retained, so applications that need that 44453541Sshin information should instead use raw inflate, see inflateInit2() below, or 44553541Sshin inflateBack() and perform their own processing of the gzip header and 446148385Sume trailer. 44753541Sshin 448148385Sume inflate() returns Z_OK if some progress has been made (more input processed 449148385Sume or more output produced), Z_STREAM_END if the end of the compressed data has 450148385Sume been reached and all uncompressed output has been produced, Z_NEED_DICT if a 451148385Sume preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 45253541Sshin corrupted (input stream not conforming to the zlib format or incorrect check 453148385Sume value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 454148385Sume if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, 455148385Sume Z_BUF_ERROR if no progress is possible or if there was not enough room in the 456148385Sume output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 457148385Sume inflate() can be called again with more input and more output space to 458148385Sume continue decompressing. If Z_DATA_ERROR is returned, the application may then 459148385Sume call inflateSync() to look for a good compression block if a partial recovery 460148385Sume of the data is desired. 461148385Sume*/ 462148385Sume 463148385Sume 464148385SumeZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 465148385Sume/* 466148385Sume All dynamically allocated data structures for this stream are freed. 467148385Sume This function discards any unprocessed input and does not flush any 468148385Sume pending output. 46953541Sshin 47053541Sshin inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 47153541Sshin was inconsistent. In the error case, msg may be set but then points to a 47253541Sshin static string (which must not be deallocated). 47353541Sshin*/ 47453541Sshin 475148385Sume /* Advanced functions */ 476148385Sume 477148385Sume/* 47853541Sshin The following functions are needed only in some special applications. 479148385Sume*/ 480148385Sume 48153541Sshin/* 482148385SumeZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 48353541Sshin int level, 48453541Sshin int method, 48553541Sshin int windowBits, 48653541Sshin int memLevel, 48753541Sshin int strategy)); 488121315Sume 48953541Sshin This is another version of deflateInit with more compression options. The 49053541Sshin fields next_in, zalloc, zfree and opaque must be initialized before by 49153541Sshin the caller. 49253541Sshin 49353541Sshin The method parameter is the compression method. It must be Z_DEFLATED in 49453541Sshin this version of the library. 49553541Sshin 49653541Sshin The windowBits parameter is the base two logarithm of the window size 49753541Sshin (the size of the history buffer). It should be in the range 8..15 for this 49853541Sshin version of the library. Larger values of this parameter result in better 49953541Sshin compression at the expense of memory usage. The default value is 15 if 50053541Sshin deflateInit is used instead. 50153541Sshin 50253541Sshin windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 50353541Sshin determines the window size. deflate() will then generate raw deflate data 50453541Sshin with no zlib header or trailer, and will not compute an adler32 check value. 50553541Sshin 50653541Sshin windowBits can also be greater than 15 for optional gzip encoding. Add 507120941Sume 16 to windowBits to write a simple gzip header and trailer around the 50853541Sshin compressed data instead of a zlib wrapper. The gzip header will have no 50953541Sshin file name, no extra data, no comment, no modification time (set to zero), 51053541Sshin no header crc, and the operating system will be set to 255 (unknown). If a 51153541Sshin gzip stream is being written, strm->adler is a crc32 instead of an adler32. 51253541Sshin 51353541Sshin The memLevel parameter specifies how much memory should be allocated 51453541Sshin for the internal compression state. memLevel=1 uses minimum memory but 51553541Sshin is slow and reduces compression ratio; memLevel=9 uses maximum memory 51653541Sshin for optimal speed. The default value is 8. See zconf.h for total memory 51753541Sshin usage as a function of windowBits and memLevel. 51853541Sshin 519120941Sume The strategy parameter is used to tune the compression algorithm. Use the 520120941Sume value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 52153541Sshin filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 522148385Sume string match), or Z_RLE to limit match distances to one (run-length 523148385Sume encoding). Filtered data consists mostly of small values with a somewhat 524148385Sume random distribution. In this case, the compression algorithm is tuned to 525148385Sume compress them better. The effect of Z_FILTERED is to force more Huffman 526148385Sume coding and less string matching; it is somewhat intermediate between 527148385Sume Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as 528148385Sume Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy 52953541Sshin parameter only affects the compression ratio but not the correctness of the 530148385Sume compressed output even if it is not set appropriately. Z_FIXED prevents the 531148385Sume use of dynamic Huffman codes, allowing for a simpler decoder for special 532148385Sume applications. 533148385Sume 534148385Sume deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 535148385Sume memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 536148385Sume method). msg is set to null if there is no error message. deflateInit2 does 537148385Sume not perform any compression: this will be done by deflate(). 53853541Sshin*/ 53953541Sshin 54053541SshinZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 54153541Sshin const Bytef *dictionary, 54253541Sshin uInt dictLength)); 54353541Sshin/* 544148987Sume Initializes the compression dictionary from the given byte sequence 54562587Sitojun without producing any compressed output. This function must be called 54662587Sitojun immediately after deflateInit, deflateInit2 or deflateReset, before any 54762587Sitojun call of deflate. The compressor and decompressor must use exactly the same 54862587Sitojun dictionary (see inflateSetDictionary). 54953541Sshin 55053541Sshin The dictionary should consist of strings (byte sequences) that are likely 55153541Sshin to be encountered later in the data to be compressed, with the most commonly 55253541Sshin used strings preferably put towards the end of the dictionary. Using a 55353541Sshin dictionary is most useful when the data to be compressed is short and can be 55453541Sshin predicted with good accuracy; the data can then be compressed better than 55553541Sshin with the default empty dictionary. 55653541Sshin 55762587Sitojun Depending on the size of the compression data structures selected by 55853541Sshin deflateInit or deflateInit2, a part of the dictionary may in effect be 55962587Sitojun discarded, for example if the dictionary is larger than the window size in 56062587Sitojun deflate or deflate2. Thus the strings most likely to be useful should be 56162587Sitojun put at the end of the dictionary, not at the front. In addition, the 56262587Sitojun current implementation of deflate will use at most the window size minus 56362587Sitojun 262 bytes of the provided dictionary. 56453541Sshin 56553541Sshin Upon return of this function, strm->adler is set to the adler32 value 56653541Sshin of the dictionary; the decompressor may later use this value to determine 56753541Sshin which dictionary has been used by the compressor. (The adler32 value 56853541Sshin applies to the whole dictionary even if only a subset of the dictionary is 56953541Sshin actually used by the compressor.) If a raw deflate was requested, then the 57053541Sshin adler32 value is not computed and strm->adler is not set. 57153541Sshin 57253541Sshin deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 57378064Sume parameter is invalid (such as NULL dictionary) or the stream state is 57478064Sume inconsistent (for example if deflate has already been called for this stream 57578064Sume or if the compression method is bsort). deflateSetDictionary does not 57678064Sume perform any compression: this will be done by deflate(). 57778064Sume*/ 57862587Sitojun 57962587SitojunZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 58062587Sitojun z_streamp source)); 58162587Sitojun/* 58262587Sitojun Sets the destination stream as a complete copy of the source stream. 58362587Sitojun 58462587Sitojun This function can be useful when several compression strategies will be 58562587Sitojun tried, for example when there are several ways of pre-processing the input 58662587Sitojun data with a filter. The streams that will be discarded should then be freed 58753541Sshin by calling deflateEnd. Note that deflateCopy duplicates the internal 58853541Sshin compression state which can be quite large, so this strategy is slow and 58962587Sitojun can consume lots of memory. 590148385Sume 59162587Sitojun deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 59262587Sitojun enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 59362587Sitojun (such as zalloc being NULL). msg is left unchanged in both source and 59462587Sitojun destination. 59553541Sshin*/ 596148385Sume 597148385SumeZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 598150202Ssuz/* 59953541Sshin This function is equivalent to deflateEnd followed by deflateInit, 60053541Sshin but does not free and reallocate all the internal compression state. 60178064Sume The stream will keep the same compression level and any other attributes 60253541Sshin that may have been set by deflateInit2. 60378064Sume 60478064Sume deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 60553541Sshin stream state was inconsistent (such as zalloc or state being NULL). 60653541Sshin*/ 60753541Sshin 60878064SumeZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 60978064Sume int level, 61078064Sume int strategy)); 61153541Sshin/* 61253541Sshin Dynamically update the compression level and compression strategy. The 61353541Sshin interpretation of level and strategy is as in deflateInit2. This can be 61453541Sshin used to switch between compression and straight copy of the input data, or 61553541Sshin to switch to a different kind of input data requiring a different 61678064Sume strategy. If the compression level is changed, the input available so far 61778064Sume is compressed with the old level (and may be flushed); the new level will 61878064Sume take effect only at the next call of deflate(). 61962587Sitojun 62053541Sshin Before the call of deflateParams, the stream state must be set as for 62153541Sshin a call of deflate(), since the currently available input may have to 62253541Sshin be compressed and flushed. In particular, strm->avail_out must be non-zero. 62353541Sshin 62453541Sshin deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 62553541Sshin stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 62653541Sshin if strm->avail_out was zero. 62753541Sshin*/ 62853541Sshin 62953541SshinZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 63053541Sshin int good_length, 63153541Sshin int max_lazy, 63253541Sshin int nice_length, 63353541Sshin int max_chain)); 63453541Sshin/* 63553541Sshin Fine tune deflate's internal compression parameters. This should only be 63653541Sshin used by someone who understands the algorithm used by zlib's deflate for 63753541Sshin searching for the best matching string, and even then only by the most 63853541Sshin fanatic optimizer trying to squeeze out the last compressed bit for their 63953541Sshin specific input data. Read the deflate.c source code for the meaning of the 64053541Sshin max_lazy, good_length, nice_length, and max_chain parameters. 64162587Sitojun 64253541Sshin deflateTune() can be called after deflateInit() or deflateInit2(), and 64353541Sshin returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 64495023Ssuz */ 64553541Sshin 64653541SshinZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 64753541Sshin uLong sourceLen)); 64853541Sshin/* 64962587Sitojun deflateBound() returns an upper bound on the compressed size after 65053541Sshin deflation of sourceLen bytes. It must be called after deflateInit() 65153541Sshin or deflateInit2(). This would be used to allocate an output buffer 65253541Sshin for deflation in a single pass, and so would be called before deflate(). 653120941Sume*/ 654120941Sume 655120941SumeZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 65678064Sume int bits, 65753541Sshin int value)); 65853541Sshin/* 65953541Sshin deflatePrime() inserts bits in the deflate output stream. The intent 660120941Sume is that this function is used to start off the deflate output with the 661120941Sume bits leftover from a previous deflate stream when appending to it. As such, 66253541Sshin this function can only be used for raw deflate, and must be used before the 66353541Sshin first deflate() call after a deflateInit2() or deflateReset(). bits must be 66453541Sshin less than or equal to 16, and that many of the least significant bits of 66553541Sshin value will be inserted in the output. 66653541Sshin 66762587Sitojun deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 66853541Sshin stream state was inconsistent. 66953541Sshin*/ 67053541Sshin 67153541SshinZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 67253541Sshin gz_headerp head)); 67353541Sshin/* 674151465Ssuz deflateSetHeader() provides gzip header information for when a gzip 67562587Sitojun stream is requested by deflateInit2(). deflateSetHeader() may be called 67653541Sshin after deflateInit2() or deflateReset() and before the first call of 67753541Sshin deflate(). The text, time, os, extra field, name, and comment information 67853541Sshin in the provided gz_header structure are written to the gzip header (xflag is 67953541Sshin ignored -- the extra flags are set according to the compression level). The 68053541Sshin caller must assure that, if not Z_NULL, name and comment are terminated with 68153541Sshin a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 68253541Sshin available there. If hcrc is true, a gzip header crc is included. Note that 68353541Sshin the current versions of the command-line version of gzip (up through version 68462587Sitojun 1.3.x) do not support header crc's, and will report that it is a "multi-part 685120941Sume gzip file" and give up. 68653541Sshin 687121161Sume If deflateSetHeader is not used, the default gzip header has text false, 688120941Sume the time set to zero, and os set to 255, with no extra, name, or comment 68978064Sume fields. The gzip header is returned to the default state by deflateReset(). 69053541Sshin 69178064Sume deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 69278064Sume stream state was inconsistent. 69378064Sume*/ 69478064Sume 69578064Sume/* 69678064SumeZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 69778064Sume int windowBits)); 69878064Sume 69978064Sume This is another version of inflateInit with an extra parameter. The 70078064Sume fields next_in, avail_in, zalloc, zfree and opaque must be initialized 70153541Sshin before by the caller. 70253541Sshin 70353541Sshin The windowBits parameter is the base two logarithm of the maximum window 70453541Sshin size (the size of the history buffer). It should be in the range 8..15 for 70553541Sshin this version of the library. The default value is 15 if inflateInit is used 70653541Sshin instead. windowBits must be greater than or equal to the windowBits value 707151465Ssuz provided to deflateInit2() while compressing, or it must be equal to 15 if 70853541Sshin deflateInit2() was not used. If a compressed stream with a larger window 70953541Sshin size is given as input, inflate() will return with the error code 71053541Sshin Z_DATA_ERROR instead of trying to allocate a larger window. 71153541Sshin 71253541Sshin windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 71353541Sshin determines the window size. inflate() will then process raw deflate data, 71453541Sshin not looking for a zlib or gzip header, not generating a check value, and not 71553541Sshin looking for any check values for comparison at the end of the stream. This 71653541Sshin is for use with other formats that use the deflate compressed data format 71753541Sshin such as zip. Those formats provide their own check values. If a custom 71853541Sshin format is developed using the raw deflate format for compressed data, it is 71953541Sshin recommended that a check value such as an adler32 or a crc32 be applied to 72053541Sshin the uncompressed data as is done in the zlib, gzip, and zip formats. For 72153541Sshin most applications, the zlib format should be used as is. Note that comments 72253541Sshin above on the use in deflateInit2() applies to the magnitude of windowBits. 72353541Sshin 72453541Sshin windowBits can also be greater than 15 for optional gzip decoding. Add 72553541Sshin 32 to windowBits to enable zlib and gzip decoding with automatic header 72653541Sshin detection, or add 16 to decode only the gzip format (the zlib format will 72753541Sshin return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 72853541Sshin a crc32 instead of an adler32. 72953541Sshin 73053541Sshin inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 73153541Sshin memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg 73253541Sshin is set to null if there is no error message. inflateInit2 does not perform 73353541Sshin any decompression apart from reading the zlib header if present: this will 73453541Sshin be done by inflate(). (So next_in and avail_in may be modified, but next_out 73553541Sshin and avail_out are unchanged.) 73653541Sshin*/ 73753541Sshin 738151465SsuzZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 73953541Sshin const Bytef *dictionary, 74053541Sshin uInt dictLength)); 74153541Sshin/* 74253541Sshin Initializes the decompression dictionary from the given uncompressed byte 74378064Sume sequence. This function must be called immediately after a call of inflate, 74453541Sshin if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 74578064Sume can be determined from the adler32 value returned by that call of inflate. 74678064Sume The compressor and decompressor must use exactly the same dictionary (see 74762587Sitojun deflateSetDictionary). For raw inflate, this function can be called 74853541Sshin immediately after inflateInit2() or inflateReset() and before any call of 749151465Ssuz inflate() to set the dictionary. The application must insure that the 750151465Ssuz dictionary that was used for compression is provided. 75153541Sshin 75253541Sshin inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 75353541Sshin parameter is invalid (such as NULL dictionary) or the stream state is 754151465Ssuz inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 75553541Sshin expected one (incorrect adler32 value). inflateSetDictionary does not 75653541Sshin perform any decompression: this will be done by subsequent calls of 75753541Sshin inflate(). 75853541Sshin*/ 75953541Sshin 76053541SshinZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 76153541Sshin/* 76253541Sshin Skips invalid compressed data until a full flush point (see above the 76353541Sshin description of deflate with Z_FULL_FLUSH) can be found, or until all 76453541Sshin available input is skipped. No output is provided. 76553541Sshin 76662587Sitojun inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 76753541Sshin if no more input was provided, Z_DATA_ERROR if no flush point has been found, 76853541Sshin or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 769121161Sume case, the application may save the current current value of total_in which 77053541Sshin indicates where valid compressed data was found. In the error case, the 77153541Sshin application may repeatedly call inflateSync, providing more input each time, 772151465Ssuz until success or end of the input data. 77353541Sshin*/ 77478064Sume 77578064SumeZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 77653541Sshin z_streamp source)); 77753541Sshin/* 77853541Sshin Sets the destination stream as a complete copy of the source stream. 77953541Sshin 78053541Sshin This function can be useful when randomly accessing a large stream. The 78153541Sshin first pass through the stream can periodically record the inflate state, 78253541Sshin allowing restarting inflate at those points when randomly accessing the 78353541Sshin stream. 78453541Sshin 78553541Sshin inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 78653541Sshin enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 78753541Sshin (such as zalloc being NULL). msg is left unchanged in both source and 78853541Sshin destination. 78953541Sshin*/ 79095023Ssuz 79195023SsuzZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 79295023Ssuz/* 79395023Ssuz This function is equivalent to inflateEnd followed by inflateInit, 79495023Ssuz but does not free and reallocate all the internal decompression state. 795120941Sume The stream will keep attributes that may have been set by inflateInit2. 79695023Ssuz 79753541Sshin inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 798128422Sluigi stream state was inconsistent (such as zalloc or state being NULL). 79953541Sshin*/ 80053541Sshin 80153541SshinZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 80253541Sshin int bits, 80353541Sshin int value)); 80453541Sshin/* 80553541Sshin This function inserts bits in the inflate input stream. The intent is 80653541Sshin that this function is used to start inflating at a bit position in the 80753541Sshin middle of a byte. The provided bits will be used before any bytes are used 80853541Sshin from next_in. This function should only be used with raw inflate, and 809128422Sluigi should be used before the first inflate() call after inflateInit2() or 81053541Sshin inflateReset(). bits must be less than or equal to 16, and that many of the 81153541Sshin least significant bits of value will be inserted in the input. 81253541Sshin 81353541Sshin inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 81453541Sshin stream state was inconsistent. 81553541Sshin*/ 81653541Sshin 81753541SshinZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 81862587Sitojun gz_headerp head)); 81995023Ssuz/* 82062587Sitojun inflateGetHeader() requests that gzip header information be stored in the 82162587Sitojun provided gz_header structure. inflateGetHeader() may be called after 82262587Sitojun inflateInit2() or inflateReset(), and before the first call of inflate(). 82353541Sshin As inflate() processes the gzip stream, head->done is zero until the header 824120941Sume is completed, at which time head->done is set to one. If a zlib stream is 82553541Sshin being decoded, then head->done is set to -1 to indicate that there will be 82662587Sitojun no gzip header information forthcoming. Note that Z_BLOCK can be used to 82762587Sitojun force inflate() to return immediately after header processing is complete 82862587Sitojun and before any actual data is decompressed. 82978064Sume 83078064Sume The text, time, xflags, and os fields are filled in with the gzip header 83178064Sume contents. hcrc is set to true if there is a header CRC. (The header CRC 83278064Sume was valid if done is set to one.) If extra is not Z_NULL, then extra_max 83378064Sume contains the maximum number of bytes to write to extra. Once done is true, 83453541Sshin extra_len contains the actual extra field length, and extra contains the 83553541Sshin extra field, or that field truncated if extra_max is less than extra_len. 83653541Sshin If name is not Z_NULL, then up to name_max characters are written there, 83753541Sshin terminated with a zero unless the length is greater than name_max. If 83853541Sshin comment is not Z_NULL, then up to comm_max characters are written there, 83953541Sshin terminated with a zero unless the length is greater than comm_max. When 84053541Sshin any of extra, name, or comment are not Z_NULL and the respective field is 84162587Sitojun not present in the header, then that field is set to Z_NULL to signal its 84262587Sitojun absence. This allows the use of deflateSetHeader() with the returned 84362587Sitojun structure to duplicate the header. However if those fields are set to 84453541Sshin allocated memory, then the application will need to save those pointers 84553541Sshin elsewhere so that they can be eventually freed. 846148385Sume 84753541Sshin If inflateGetHeader is not used, then the header information is simply 848148385Sume discarded. The header is always checked for validity, including the header 84953541Sshin CRC if present. inflateReset() will reset the process to discard the header 85062587Sitojun information. The application would need to call inflateGetHeader() again to 85162587Sitojun retrieve the header from the next gzip stream. 85253541Sshin 85353541Sshin inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 85453541Sshin stream state was inconsistent. 85553541Sshin*/ 85653541Sshin 857148385Sume/* 858148385SumeZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 859148385Sume unsigned char FAR *window)); 86092733Speter 861148385Sume Initialize the internal stream state for decompression using inflateBack() 86262587Sitojun calls. The fields zalloc, zfree and opaque in strm must be initialized 863148385Sume before the call. If zalloc and zfree are Z_NULL, then the default library- 864148385Sume derived memory allocation routines are used. windowBits is the base two 865148385Sume logarithm of the window size, in the range 8..15. window is a caller 866148385Sume supplied buffer of that size. Except for special applications where it is 86762587Sitojun assured that deflate was used with small window sizes, windowBits must be 15 86862587Sitojun and a 32K byte window must be supplied to be able to decompress general 86962587Sitojun deflate streams. 87062587Sitojun 87162587Sitojun See inflateBack() for the usage of these routines. 87262587Sitojun 87362587Sitojun inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 87462587Sitojun the paramaters are invalid, Z_MEM_ERROR if the internal state could not 87553541Sshin be allocated, or Z_VERSION_ERROR if the version of the library does not 87662587Sitojun match the version of the header file. 87753541Sshin*/ 878111119Simp 87962587Sitojuntypedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 880111119Simptypedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 88162587Sitojun 88262587SitojunZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 88362587Sitojun in_func in, void FAR *in_desc, 88462587Sitojun out_func out, void FAR *out_desc)); 88562587Sitojun/* 88662587Sitojun inflateBack() does a raw inflate with a single call using a call-back 88762587Sitojun interface for input and output. This is more efficient than inflate() for 88878064Sume file i/o applications in that it avoids copying between the output and the 88962587Sitojun sliding window by simply making the window itself the output buffer. This 890148385Sume function trusts the application to not change the output buffer passed by 89153541Sshin the output function, at least until inflateBack() returns. 89253541Sshin 89353541Sshin inflateBackInit() must be called first to allocate the internal state 89453541Sshin and to initialize the state with the user-provided window buffer. 89553541Sshin inflateBack() may then be used multiple times to inflate a complete, raw 89653541Sshin deflate stream with each call. inflateBackEnd() is then called to free 89753541Sshin the allocated state. 89853541Sshin 89995023Ssuz A raw deflate stream is one with no zlib or gzip header or trailer. 90053541Sshin This routine would normally be used in a utility that reads zip or gzip 90153541Sshin files and writes out uncompressed files. The utility would decode the 90253541Sshin header and process the trailer on its own, hence this routine expects 90353541Sshin only the raw deflate stream to decompress. This is different from the 90462587Sitojun normal behavior of inflate(), which expects either a zlib or gzip header and 90562587Sitojun trailer around the deflate stream. 90653541Sshin 90753541Sshin inflateBack() uses two subroutines supplied by the caller that are then 908148385Sume called by inflateBack() for input and output. inflateBack() calls those 90953541Sshin routines until it reads a complete deflate stream and writes out all of the 91053541Sshin uncompressed data, or until it encounters an error. The function's 911148385Sume parameters and return types are defined above in the in_func and out_func 91253541Sshin typedefs. inflateBack() will call in(in_desc, &buf) which should return the 91353541Sshin number of bytes of provided input, and a pointer to that input in buf. If 91453541Sshin there is no input available, in() must return zero--buf is ignored in that 915148385Sume case--and inflateBack() will return a buffer error. inflateBack() will call 916148385Sume out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 917148385Sume should return zero on success, or non-zero on failure. If out() returns 91853541Sshin non-zero, inflateBack() will return with an error. Neither in() nor out() 919148385Sume are permitted to change the contents of the window provided to 920148385Sume inflateBackInit(), which is also the buffer that out() uses to write from. 921148385Sume The length written by out() will be at most the window size. Any non-zero 922148385Sume amount of input may be provided by in(). 923148385Sume 924148385Sume For convenience, inflateBack() can be provided input on the first call by 92553541Sshin setting strm->next_in and strm->avail_in. If that input is exhausted, then 92653541Sshin in() will be called. Therefore strm->next_in must be initialized before 92753541Sshin calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 92853541Sshin immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 929148385Sume must also be initialized, and then if strm->avail_in is not zero, input will 930148385Sume initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 931148385Sume 932148385Sume The in_desc and out_desc parameters of inflateBack() is passed as the 933148385Sume first parameter of in() and out() respectively when they are called. These 934148385Sume descriptors can be optionally used to pass any information that the caller- 935148385Sume supplied in() and out() functions need to do their job. 93653541Sshin 937148385Sume On return, inflateBack() will set strm->next_in and strm->avail_in to 93853541Sshin pass back any unused input that was provided by the last in() call. The 93953541Sshin return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 94053541Sshin if in() or out() returned an error, Z_DATA_ERROR if there was a format 94153541Sshin error in the deflate stream (in which case strm->msg is set to indicate the 942121315Sume nature of the error), or Z_STREAM_ERROR if the stream was not properly 94353541Sshin initialized. In the case of Z_BUF_ERROR, an input or output error can be 94453541Sshin distinguished using strm->next_in which will be Z_NULL only if in() returned 94553541Sshin an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to 94653541Sshin out() returning non-zero. (in() will always be called before out(), so 94753541Sshin strm->next_in is assured to be defined if out() returns non-zero.) Note 94853541Sshin that inflateBack() cannot return Z_OK. 94953541Sshin*/ 95062587Sitojun 95162587SitojunZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 95262587Sitojun/* 95362587Sitojun All memory allocated by inflateBackInit() is freed. 95462587Sitojun 95562587Sitojun inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 956142215Sglebius state was inconsistent. 957142215Sglebius*/ 958142215Sglebius 959142215SglebiusZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 960142215Sglebius/* Return flags indicating compile-time options. 961142215Sglebius 962142215Sglebius Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 96362587Sitojun 1.0: size of uInt 964142215Sglebius 3.2: size of uLong 965142215Sglebius 5.4: size of voidpf (pointer) 96662587Sitojun 7.6: size of z_off_t 96762587Sitojun 96862587Sitojun Compiler, assembler, and debug options: 96962587Sitojun 8: DEBUG 97062587Sitojun 9: ASMV or ASMINF -- use ASM code 97162587Sitojun 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 97262587Sitojun 11: 0 (reserved) 97353541Sshin 97453541Sshin One-time table building (smaller code, but not thread-safe if true): 975120941Sume 12: BUILDFIXED -- build static block decoding tables when needed 97653541Sshin 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 97753541Sshin 14,15: 0 (reserved) 97853541Sshin 97953541Sshin Library content (indicates missing functionality): 98053541Sshin 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 98153541Sshin deflate code when not needed) 98253541Sshin 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 98353541Sshin and decode gzip streams (to avoid linking crc code) 98453541Sshin 18-19: 0 (reserved) 98553541Sshin 98653541Sshin Operation variations (changes in library functionality): 98753541Sshin 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 98853541Sshin 21: FASTEST -- deflate algorithm with only one, lowest compression level 98953541Sshin 22,23: 0 (reserved) 99053541Sshin 99153541Sshin The sprintf variant used by gzprintf (zero is best): 99253541Sshin 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 993120941Sume 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 99453541Sshin 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 995148385Sume 996148385Sume Remainder: 997148385Sume 27-31: 0 (reserved) 998148385Sume */ 999148385Sume 1000148385Sume 1001148385Sume /* utility functions */ 100253541Sshin 1003148385Sume/* 1004148385Sume The following utility functions are implemented on top of the 1005148385Sume basic stream-oriented functions. To simplify the interface, some 1006148385Sume default options are assumed (compression level and memory usage, 1007148385Sume standard memory allocation functions). The source code of these 1008148385Sume utility functions can easily be modified if you need special options. 1009148385Sume*/ 1010148385Sume 101153541SshinZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 101253541Sshin const Bytef *source, uLong sourceLen)); 101353541Sshin/* 101453541Sshin Compresses the source buffer into the destination buffer. sourceLen is 101553541Sshin the byte length of the source buffer. Upon entry, destLen is the total 101653541Sshin size of the destination buffer, which must be at least the value returned 101753541Sshin by compressBound(sourceLen). Upon exit, destLen is the actual size of the 101853541Sshin compressed buffer. 101953541Sshin This function can be used to compress a whole file at once if the 102053541Sshin input file is mmap'ed. 102178064Sume compress returns Z_OK if success, Z_MEM_ERROR if there was not 102278468Ssumikawa enough memory, Z_BUF_ERROR if there was not enough room in the output 102378468Ssumikawa buffer. 102478468Ssumikawa*/ 102578064Sume 102678064SumeZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 102778064Sume const Bytef *source, uLong sourceLen, 1028142215Sglebius int level)); 1029142215Sglebius/* 1030142215Sglebius Compresses the source buffer into the destination buffer. The level 1031149829Sthompsa parameter has the same meaning as in deflateInit. sourceLen is the byte 1032120049Smdodd length of the source buffer. Upon entry, destLen is the total size of the 1033147306Sbrooks destination buffer, which must be at least the value returned by 103453541Sshin compressBound(sourceLen). Upon exit, destLen is the actual size of the 103553541Sshin compressed buffer. 103653541Sshin 103753541Sshin compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 103853541Sshin memory, Z_BUF_ERROR if there was not enough room in the output buffer, 103960938Sjake Z_STREAM_ERROR if the level parameter is invalid. 104053541Sshin*/ 104160938Sjake 104253541SshinZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 104353541Sshin/* 104462587Sitojun compressBound() returns an upper bound on the compressed size after 104553541Sshin compress() or compress2() on sourceLen bytes. It would be used before 104653541Sshin a compress() or compress2() call to allocate the destination buffer. 104753541Sshin*/ 104878064Sume 104953541SshinZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 105053541Sshin const Bytef *source, uLong sourceLen)); 105153541Sshin/* 105278064Sume Decompresses the source buffer into the destination buffer. sourceLen is 105353541Sshin the byte length of the source buffer. Upon entry, destLen is the total 105453541Sshin size of the destination buffer, which must be large enough to hold the 105553541Sshin entire uncompressed data. (The size of the uncompressed data must have 105653541Sshin been saved previously by the compressor and transmitted to the decompressor 105753541Sshin by some mechanism outside the scope of this compression library.) 105853541Sshin Upon exit, destLen is the actual size of the compressed buffer. 105953541Sshin This function can be used to decompress a whole file at once if the 106062587Sitojun input file is mmap'ed. 106153541Sshin 106253541Sshin uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 106353541Sshin enough memory, Z_BUF_ERROR if there was not enough room in the output 106453541Sshin buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. 106553541Sshin*/ 106653541Sshin 106778064Sume 106878064Sumetypedef voidp gzFile; 106978064Sume 107078064SumeZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 107178064Sume/* 107278064Sume Opens a gzip (.gz) file for reading or writing. The mode parameter 107378064Sume is as in fopen ("rb" or "wb") but can also include a compression level 107478064Sume ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 107578064Sume Huffman only compression as in "wb1h", or 'R' for run-length encoding 107678064Sume as in "wb1R". (See the description of deflateInit2 for more information 107778064Sume about the strategy parameter.) 107878064Sume 107978064Sume gzopen can be used to read a file which is not in gzip format; in this 108078064Sume case gzread will directly read from the file without decompression. 108178064Sume 108278064Sume gzopen returns NULL if the file could not be opened or if there was 108378064Sume insufficient memory to allocate the (de)compression state; errno 108478064Sume can be checked to distinguish the two cases (if errno is zero, the 108553541Sshin zlib error is Z_MEM_ERROR). */ 1086148987Sume 108753541SshinZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 108853541Sshin/* 108953541Sshin gzdopen() associates a gzFile with the file descriptor fd. File 109053541Sshin descriptors are obtained from calls like open, dup, creat, pipe or 109153541Sshin fileno (in the file has been previously opened with fopen). 109253541Sshin The mode parameter is as in gzopen. 109353541Sshin The next call of gzclose on the returned gzFile will also close the 109453541Sshin file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 109553541Sshin descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 109653541Sshin gzdopen returns NULL if there was insufficient memory to allocate 109753541Sshin the (de)compression state. 109853541Sshin*/ 109953541Sshin 110053541SshinZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 110153541Sshin/* 110253541Sshin Dynamically update the compression level or strategy. See the description 110353541Sshin of deflateInit2 for the meaning of these parameters. 110453541Sshin gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 110553541Sshin opened for writing. 110653541Sshin*/ 110753541Sshin 110862587SitojunZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 110962587Sitojun/* 111053541Sshin Reads the given number of uncompressed bytes from the compressed file. 111153541Sshin If the input file was not in gzip format, gzread copies the given number 111253541Sshin of bytes into the buffer. 111353541Sshin gzread returns the number of uncompressed bytes actually read (0 for 111453541Sshin end of file, -1 for error). */ 111553541Sshin 111653541SshinZEXTERN int ZEXPORT gzwrite OF((gzFile file, 111753541Sshin voidpc buf, unsigned len)); 111853541Sshin/* 111953541Sshin Writes the given number of uncompressed bytes into the compressed file. 112053541Sshin gzwrite returns the number of uncompressed bytes actually written 112153541Sshin (0 in case of error). 112253541Sshin*/ 1123151465Ssuz 112453541SshinZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 1125120941Sume/* 112653541Sshin Converts, formats, and writes the args to the compressed file under 1127120941Sume control of the format string, as in fprintf. gzprintf returns the number of 112853541Sshin uncompressed bytes actually written (0 in case of error). The number of 112953541Sshin uncompressed bytes written is limited to 4095. The caller should assure that 113053541Sshin this limit is not exceeded. If it is exceeded, then gzprintf() will return 113153541Sshin return an error (0) with nothing written. In this case, there may also be a 113253541Sshin buffer overflow with unpredictable consequences, which is possible only if 113353541Sshin zlib was compiled with the insecure functions sprintf() or vsprintf() 113453541Sshin because the secure snprintf() or vsnprintf() functions were not available. 113562587Sitojun*/ 113653541Sshin 113753541SshinZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 113853541Sshin/* 113953541Sshin Writes the given null-terminated string to the compressed file, excluding 114053541Sshin the terminating null character. 114153541Sshin gzputs returns the number of characters written, or -1 in case of error. 114278064Sume*/ 114353541Sshin 114453541SshinZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 114578064Sume/* 114678064Sume Reads bytes from the compressed file until len-1 characters are read, or 114753541Sshin a newline character is read and transferred to buf, or an end-of-file 114853541Sshin condition is encountered. The string is then terminated with a null 114953541Sshin character. 115053541Sshin gzgets returns buf, or Z_NULL in case of error. 115153541Sshin*/ 115253541Sshin 115353541SshinZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 115453541Sshin/* 115595023Ssuz Writes c, converted to an unsigned char, into the compressed file. 115653541Sshin gzputc returns the value that was written, or -1 in case of error. 115753541Sshin*/ 115862587Sitojun 115995023SsuzZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 116062587Sitojun/* 1161121161Sume Reads one byte from the compressed file. gzgetc returns this byte 1162121161Sume or -1 in case of end of file or error. 116353541Sshin*/ 116453541Sshin 116553541SshinZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 116653541Sshin/* 1167121807Sume Push one character back onto the stream to be read again later. 116853541Sshin Only one character of push-back is allowed. gzungetc() returns the 1169121807Sume character pushed, or -1 on failure. gzungetc() will fail if a 117053541Sshin character has been pushed but not read yet, or if c is -1. The pushed 117178064Sume character will be discarded if the stream is repositioned with gzseek() 117253541Sshin or gzrewind(). 117353541Sshin*/ 117453541Sshin 117578064SumeZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 117678064Sume/* 117778064Sume Flushes all pending output into the compressed file. The parameter 117878064Sume flush is as in the deflate() function. The return value is the zlib 117978064Sume error number (see function gzerror below). gzflush returns Z_OK if 118078064Sume the flush parameter is Z_FINISH and all output could be flushed. 118178064Sume gzflush should be called only when strictly necessary because it can 118278064Sume degrade compression. 118378064Sume*/ 118478064Sume 118578064SumeZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 118678064Sume z_off_t offset, int whence)); 118778064Sume/* 118878064Sume Sets the starting position for the next gzread or gzwrite on the 118978064Sume given compressed file. The offset represents a number of bytes in the 119078064Sume uncompressed data stream. The whence parameter is defined as in lseek(2); 119178064Sume the value SEEK_END is not supported. 119278064Sume If the file is opened for reading, this function is emulated but can be 119378064Sume extremely slow. If the file is opened for writing, only forward seeks are 119478064Sume supported; gzseek then compresses a sequence of zeroes up to the new 119578064Sume starting position. 119678064Sume 119778064Sume gzseek returns the resulting offset location as measured in bytes from 119878064Sume the beginning of the uncompressed stream, or -1 in case of error, in 119978064Sume particular if the file is opened for writing and the new starting position 120053541Sshin would be before the current position. 120153541Sshin*/ 120253541Sshin 120353541SshinZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 120453541Sshin/* 120553541Sshin Rewinds the given file. This function is supported only for reading. 120653541Sshin 120753541Sshin gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 120895023Ssuz*/ 120953541Sshin 121053541SshinZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 121153541Sshin/* 121262587Sitojun Returns the starting position for the next gzread or gzwrite on the 121353541Sshin given compressed file. This position represents a number of bytes in the 121453541Sshin uncompressed data stream. 121553541Sshin 121653541Sshin gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 121762587Sitojun*/ 121853541Sshin 121953541SshinZEXTERN int ZEXPORT gzeof OF((gzFile file)); 122053541Sshin/* 122162587Sitojun Returns 1 when EOF has previously been detected reading the given 122253541Sshin input stream, otherwise zero. 122353541Sshin*/ 122453541Sshin 122553541SshinZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 122653541Sshin/* 122753541Sshin Returns 1 if file is being read directly without decompression, otherwise 122862587Sitojun zero. 122953541Sshin*/ 123053541Sshin 123153541SshinZEXTERN int ZEXPORT gzclose OF((gzFile file)); 123253541Sshin/* 123353541Sshin Flushes all pending output if necessary, closes the compressed file 123453541Sshin and deallocates all the (de)compression state. The return value is the zlib 123562587Sitojun error number (see function gzerror below). 123662587Sitojun*/ 123778064Sume 1238120941SumeZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 123962587Sitojun/* 124062587Sitojun Returns the error message for the last error which occurred on the 124162587Sitojun given compressed file. errnum is set to zlib error number. If an 124262587Sitojun error occurred in the file system and not in the compression library, 124362587Sitojun errnum is set to Z_ERRNO and the application may consult errno 124462587Sitojun to get the exact error code. 124562587Sitojun*/ 124662587Sitojun 124753541SshinZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 124853541Sshin/* 124953541Sshin Clears the error and end-of-file flags for file. This is analogous to the 125053541Sshin clearerr() function in stdio. This is useful for continuing to read a gzip 125153541Sshin file that is being written concurrently. 125262587Sitojun*/ 1253120941Sume 1254121161Sume /* checksum functions */ 125553541Sshin 125653541Sshin/* 125753541Sshin These functions are not related to compression but are exported 125853541Sshin anyway because they might be useful in applications using the 125953541Sshin compression library. 126053541Sshin*/ 126153541Sshin 126253541SshinZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 126353541Sshin/* 126453541Sshin Update a running Adler-32 checksum with the bytes buf[0..len-1] and 126553541Sshin return the updated checksum. If buf is NULL, this function returns 126653541Sshin the required initial value for the checksum. 126753541Sshin An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 126853541Sshin much faster. Usage example: 126953541Sshin 127053541Sshin uLong adler = adler32(0L, Z_NULL, 0); 127153541Sshin 127253541Sshin while (read_buffer(buffer, length) != EOF) { 127353541Sshin adler = adler32(adler, buffer, length); 127453541Sshin } 127553541Sshin if (adler != original_adler) error(); 127653541Sshin*/ 127753541Sshin 127853541SshinZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 127953541Sshin z_off_t len2)); 128053541Sshin/* 128153541Sshin Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 128253541Sshin and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 128353541Sshin each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 1284148987Sume seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. 128553541Sshin*/ 128653541Sshin 128753541SshinZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 128878064Sume/* 128962587Sitojun Update a running CRC-32 with the bytes buf[0..len-1] and return the 129062587Sitojun updated CRC-32. If buf is NULL, this function returns the required initial 129178064Sume value for the for the crc. Pre- and post-conditioning (one's complement) is 129253541Sshin performed within this function so it shouldn't be done by the application. 129353541Sshin Usage example: 129453541Sshin 129553541Sshin uLong crc = crc32(0L, Z_NULL, 0); 129662587Sitojun 129753541Sshin while (read_buffer(buffer, length) != EOF) { 129853541Sshin crc = crc32(crc, buffer, length); 129953541Sshin } 130053541Sshin if (crc != original_crc) error(); 130153541Sshin*/ 130253541Sshin 130353541SshinZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 130453541Sshin 130553541Sshin/* 130653541Sshin Combine two CRC-32 check values into one. For two sequences of bytes, 130753541Sshin seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 130853541Sshin calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 130953541Sshin check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 131053541Sshin len2. 131153541Sshin*/ 131253541Sshin 131362587Sitojun 131453541Sshin /* various hacks, don't look :) */ 131553541Sshin 131653541Sshin/* deflateInit and inflateInit are macros to allow checking the zlib version 131778064Sume * and the compiler's view of z_stream: 131878064Sume */ 131978064SumeZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 132078064Sume const char *version, int stream_size)); 132153541SshinZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 132253541Sshin const char *version, int stream_size)); 132353541SshinZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 132453541Sshin int windowBits, int memLevel, 1325148987Sume int strategy, const char *version, 132678064Sume int stream_size)); 132753541SshinZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 132862587Sitojun const char *version, int stream_size)); 132953541SshinZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 133062587Sitojun unsigned char FAR *window, 133162587Sitojun const char *version, 133253541Sshin int stream_size)); 133353541Sshin#define deflateInit(strm, level) \ 133453541Sshin deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 133553541Sshin#define inflateInit(strm) \ 133662587Sitojun inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 133753541Sshin#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 133853541Sshin deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 133962587Sitojun (strategy), ZLIB_VERSION, sizeof(z_stream)) 134062587Sitojun#define inflateInit2(strm, windowBits) \ 134162587Sitojun inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 134262587Sitojun#define inflateBackInit(strm, windowBits, window) \ 134362587Sitojun inflateBackInit_((strm), (windowBits), (window), \ 134462587Sitojun ZLIB_VERSION, sizeof(z_stream)) 134562587Sitojun 134662587Sitojun 134762587Sitojun#if !defined(_ZUTIL_H) && !defined(NO_DUMMY_DECL) 134862587Sitojun struct internal_state {int dummy;}; /* hack for buggy compilers */ 134962587Sitojun#endif 135062587Sitojun 135162587SitojunZEXTERN const char * ZEXPORT zError OF((int)); 135262587SitojunZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); 135362587SitojunZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); 1354148887Srwatson 135562587Sitojun#ifdef __cplusplus 135662587Sitojun} 135762587Sitojun#endif 135862587Sitojun 135962587Sitojun#endif /* _ZLIB_H */ 136062587Sitojun