1ab9e68a2SToomas Soome /* zlib.h -- interface of the 'zlib' general purpose compression library 2*64c3d159SToomas Soome version 1.2.12, March 11th, 2022 3ab9e68a2SToomas Soome 4*64c3d159SToomas Soome Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler 5ab9e68a2SToomas Soome 6ab9e68a2SToomas Soome This software is provided 'as-is', without any express or implied 7ab9e68a2SToomas Soome warranty. In no event will the authors be held liable for any damages 8ab9e68a2SToomas Soome arising from the use of this software. 9ab9e68a2SToomas Soome 10ab9e68a2SToomas Soome Permission is granted to anyone to use this software for any purpose, 11ab9e68a2SToomas Soome including commercial applications, and to alter it and redistribute it 12ab9e68a2SToomas Soome freely, subject to the following restrictions: 13ab9e68a2SToomas Soome 14ab9e68a2SToomas Soome 1. The origin of this software must not be misrepresented; you must not 15ab9e68a2SToomas Soome claim that you wrote the original software. If you use this software 16ab9e68a2SToomas Soome in a product, an acknowledgment in the product documentation would be 17ab9e68a2SToomas Soome appreciated but is not required. 18ab9e68a2SToomas Soome 2. Altered source versions must be plainly marked as such, and must not be 19ab9e68a2SToomas Soome misrepresented as being the original software. 20ab9e68a2SToomas Soome 3. This notice may not be removed or altered from any source distribution. 21ab9e68a2SToomas Soome 22ab9e68a2SToomas Soome Jean-loup Gailly Mark Adler 23ab9e68a2SToomas Soome jloup@gzip.org madler@alumni.caltech.edu 24ab9e68a2SToomas Soome 25ab9e68a2SToomas Soome 26ab9e68a2SToomas Soome The data format used by the zlib library is described by RFCs (Request for 27ab9e68a2SToomas Soome Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 28ab9e68a2SToomas Soome (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). 29ab9e68a2SToomas Soome */ 30ab9e68a2SToomas Soome 31ab9e68a2SToomas Soome #ifndef ZLIB_H 32ab9e68a2SToomas Soome #define ZLIB_H 33ab9e68a2SToomas Soome 34ab9e68a2SToomas Soome #include "zconf.h" 35ab9e68a2SToomas Soome 36ab9e68a2SToomas Soome #ifdef __cplusplus 37ab9e68a2SToomas Soome extern "C" { 38ab9e68a2SToomas Soome #endif 39ab9e68a2SToomas Soome 40*64c3d159SToomas Soome #define ZLIB_VERSION "1.2.12" 41*64c3d159SToomas Soome #define ZLIB_VERNUM 0x12c0 42ab9e68a2SToomas Soome #define ZLIB_VER_MAJOR 1 43ab9e68a2SToomas Soome #define ZLIB_VER_MINOR 2 44*64c3d159SToomas Soome #define ZLIB_VER_REVISION 12 45ab9e68a2SToomas Soome #define ZLIB_VER_SUBREVISION 0 46ab9e68a2SToomas Soome 47ab9e68a2SToomas Soome /* 48ab9e68a2SToomas Soome The 'zlib' compression library provides in-memory compression and 49ab9e68a2SToomas Soome decompression functions, including integrity checks of the uncompressed data. 50ab9e68a2SToomas Soome This version of the library supports only one compression method (deflation) 51ab9e68a2SToomas Soome but other algorithms will be added later and will have the same stream 52ab9e68a2SToomas Soome interface. 53ab9e68a2SToomas Soome 54ab9e68a2SToomas Soome Compression can be done in a single step if the buffers are large enough, 55ab9e68a2SToomas Soome or can be done by repeated calls of the compression function. In the latter 56ab9e68a2SToomas Soome case, the application must provide more input and/or consume the output 57ab9e68a2SToomas Soome (providing more output space) before each call. 58ab9e68a2SToomas Soome 59ab9e68a2SToomas Soome The compressed data format used by default by the in-memory functions is 60ab9e68a2SToomas Soome the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 61ab9e68a2SToomas Soome around a deflate stream, which is itself documented in RFC 1951. 62ab9e68a2SToomas Soome 63ab9e68a2SToomas Soome The library also supports reading and writing files in gzip (.gz) format 64ab9e68a2SToomas Soome with an interface similar to that of stdio using the functions that start 65ab9e68a2SToomas Soome with "gz". The gzip format is different from the zlib format. gzip is a 66ab9e68a2SToomas Soome gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 67ab9e68a2SToomas Soome 68ab9e68a2SToomas Soome This library can optionally read and write gzip and raw deflate streams in 69ab9e68a2SToomas Soome memory as well. 70ab9e68a2SToomas Soome 71ab9e68a2SToomas Soome The zlib format was designed to be compact and fast for use in memory 72ab9e68a2SToomas Soome and on communications channels. The gzip format was designed for single- 73ab9e68a2SToomas Soome file compression on file systems, has a larger header than zlib to maintain 74ab9e68a2SToomas Soome directory information, and uses a different, slower check method than zlib. 75ab9e68a2SToomas Soome 76ab9e68a2SToomas Soome The library does not install any signal handler. The decoder checks 77ab9e68a2SToomas Soome the consistency of the compressed data, so the library should never crash 78ab9e68a2SToomas Soome even in the case of corrupted input. 79ab9e68a2SToomas Soome */ 80ab9e68a2SToomas Soome 81ab9e68a2SToomas Soome typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 82ab9e68a2SToomas Soome typedef void (*free_func) OF((voidpf opaque, voidpf address)); 83ab9e68a2SToomas Soome 84ab9e68a2SToomas Soome struct internal_state; 85ab9e68a2SToomas Soome 86ab9e68a2SToomas Soome typedef struct z_stream_s { 87ab9e68a2SToomas Soome z_const Bytef *next_in; /* next input byte */ 88ab9e68a2SToomas Soome uInt avail_in; /* number of bytes available at next_in */ 89ab9e68a2SToomas Soome uLong total_in; /* total number of input bytes read so far */ 90ab9e68a2SToomas Soome 91ab9e68a2SToomas Soome Bytef *next_out; /* next output byte will go here */ 92ab9e68a2SToomas Soome uInt avail_out; /* remaining free space at next_out */ 93ab9e68a2SToomas Soome uLong total_out; /* total number of bytes output so far */ 94ab9e68a2SToomas Soome 95ab9e68a2SToomas Soome z_const char *msg; /* last error message, NULL if no error */ 96ab9e68a2SToomas Soome struct internal_state FAR *state; /* not visible by applications */ 97ab9e68a2SToomas Soome 98ab9e68a2SToomas Soome alloc_func zalloc; /* used to allocate the internal state */ 99ab9e68a2SToomas Soome free_func zfree; /* used to free the internal state */ 100ab9e68a2SToomas Soome voidpf opaque; /* private data object passed to zalloc and zfree */ 101ab9e68a2SToomas Soome 102ab9e68a2SToomas Soome int data_type; /* best guess about the data type: binary or text 103ab9e68a2SToomas Soome for deflate, or the decoding state for inflate */ 104ab9e68a2SToomas Soome uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ 105ab9e68a2SToomas Soome uLong reserved; /* reserved for future use */ 106ab9e68a2SToomas Soome } z_stream; 107ab9e68a2SToomas Soome 108ab9e68a2SToomas Soome typedef z_stream FAR *z_streamp; 109ab9e68a2SToomas Soome 110ab9e68a2SToomas Soome /* 111ab9e68a2SToomas Soome gzip header information passed to and from zlib routines. See RFC 1952 112ab9e68a2SToomas Soome for more details on the meanings of these fields. 113ab9e68a2SToomas Soome */ 114ab9e68a2SToomas Soome typedef struct gz_header_s { 115ab9e68a2SToomas Soome int text; /* true if compressed data believed to be text */ 116ab9e68a2SToomas Soome uLong time; /* modification time */ 117ab9e68a2SToomas Soome int xflags; /* extra flags (not used when writing a gzip file) */ 118ab9e68a2SToomas Soome int os; /* operating system */ 119ab9e68a2SToomas Soome Bytef *extra; /* pointer to extra field or Z_NULL if none */ 120ab9e68a2SToomas Soome uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 121ab9e68a2SToomas Soome uInt extra_max; /* space at extra (only when reading header) */ 122ab9e68a2SToomas Soome Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 123ab9e68a2SToomas Soome uInt name_max; /* space at name (only when reading header) */ 124ab9e68a2SToomas Soome Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 125ab9e68a2SToomas Soome uInt comm_max; /* space at comment (only when reading header) */ 126ab9e68a2SToomas Soome int hcrc; /* true if there was or will be a header crc */ 127ab9e68a2SToomas Soome int done; /* true when done reading gzip header (not used 128ab9e68a2SToomas Soome when writing a gzip file) */ 129ab9e68a2SToomas Soome } gz_header; 130ab9e68a2SToomas Soome 131ab9e68a2SToomas Soome typedef gz_header FAR *gz_headerp; 132ab9e68a2SToomas Soome 133ab9e68a2SToomas Soome /* 134ab9e68a2SToomas Soome The application must update next_in and avail_in when avail_in has dropped 135ab9e68a2SToomas Soome to zero. It must update next_out and avail_out when avail_out has dropped 136ab9e68a2SToomas Soome to zero. The application must initialize zalloc, zfree and opaque before 137ab9e68a2SToomas Soome calling the init function. All other fields are set by the compression 138ab9e68a2SToomas Soome library and must not be updated by the application. 139ab9e68a2SToomas Soome 140ab9e68a2SToomas Soome The opaque value provided by the application will be passed as the first 141ab9e68a2SToomas Soome parameter for calls of zalloc and zfree. This can be useful for custom 142ab9e68a2SToomas Soome memory management. The compression library attaches no meaning to the 143ab9e68a2SToomas Soome opaque value. 144ab9e68a2SToomas Soome 145ab9e68a2SToomas Soome zalloc must return Z_NULL if there is not enough memory for the object. 146ab9e68a2SToomas Soome If zlib is used in a multi-threaded application, zalloc and zfree must be 147ab9e68a2SToomas Soome thread safe. In that case, zlib is thread-safe. When zalloc and zfree are 148ab9e68a2SToomas Soome Z_NULL on entry to the initialization function, they are set to internal 149ab9e68a2SToomas Soome routines that use the standard library functions malloc() and free(). 150ab9e68a2SToomas Soome 151ab9e68a2SToomas Soome On 16-bit systems, the functions zalloc and zfree must be able to allocate 152ab9e68a2SToomas Soome exactly 65536 bytes, but will not be required to allocate more than this if 153ab9e68a2SToomas Soome the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers 154ab9e68a2SToomas Soome returned by zalloc for objects of exactly 65536 bytes *must* have their 155ab9e68a2SToomas Soome offset normalized to zero. The default allocation function provided by this 156ab9e68a2SToomas Soome library ensures this (see zutil.c). To reduce memory requirements and avoid 157ab9e68a2SToomas Soome any allocation of 64K objects, at the expense of compression ratio, compile 158ab9e68a2SToomas Soome the library with -DMAX_WBITS=14 (see zconf.h). 159ab9e68a2SToomas Soome 160ab9e68a2SToomas Soome The fields total_in and total_out can be used for statistics or progress 161ab9e68a2SToomas Soome reports. After compression, total_in holds the total size of the 162ab9e68a2SToomas Soome uncompressed data and may be saved for use by the decompressor (particularly 163ab9e68a2SToomas Soome if the decompressor wants to decompress everything in a single step). 164ab9e68a2SToomas Soome */ 165ab9e68a2SToomas Soome 166ab9e68a2SToomas Soome /* constants */ 167ab9e68a2SToomas Soome 168ab9e68a2SToomas Soome #define Z_NO_FLUSH 0 169ab9e68a2SToomas Soome #define Z_PARTIAL_FLUSH 1 170ab9e68a2SToomas Soome #define Z_SYNC_FLUSH 2 171ab9e68a2SToomas Soome #define Z_FULL_FLUSH 3 172ab9e68a2SToomas Soome #define Z_FINISH 4 173ab9e68a2SToomas Soome #define Z_BLOCK 5 174ab9e68a2SToomas Soome #define Z_TREES 6 175ab9e68a2SToomas Soome /* Allowed flush values; see deflate() and inflate() below for details */ 176ab9e68a2SToomas Soome 177ab9e68a2SToomas Soome #define Z_OK 0 178ab9e68a2SToomas Soome #define Z_STREAM_END 1 179ab9e68a2SToomas Soome #define Z_NEED_DICT 2 180ab9e68a2SToomas Soome #define Z_ERRNO (-1) 181ab9e68a2SToomas Soome #define Z_STREAM_ERROR (-2) 182ab9e68a2SToomas Soome #define Z_DATA_ERROR (-3) 183ab9e68a2SToomas Soome #define Z_MEM_ERROR (-4) 184ab9e68a2SToomas Soome #define Z_BUF_ERROR (-5) 185ab9e68a2SToomas Soome #define Z_VERSION_ERROR (-6) 186ab9e68a2SToomas Soome /* Return codes for the compression/decompression functions. Negative values 187ab9e68a2SToomas Soome * are errors, positive values are used for special but normal events. 188ab9e68a2SToomas Soome */ 189ab9e68a2SToomas Soome 190ab9e68a2SToomas Soome #define Z_NO_COMPRESSION 0 191ab9e68a2SToomas Soome #define Z_BEST_SPEED 1 192ab9e68a2SToomas Soome #define Z_BEST_COMPRESSION 9 193ab9e68a2SToomas Soome #define Z_DEFAULT_COMPRESSION (-1) 194ab9e68a2SToomas Soome /* compression levels */ 195ab9e68a2SToomas Soome 196ab9e68a2SToomas Soome #define Z_FILTERED 1 197ab9e68a2SToomas Soome #define Z_HUFFMAN_ONLY 2 198ab9e68a2SToomas Soome #define Z_RLE 3 199ab9e68a2SToomas Soome #define Z_FIXED 4 200ab9e68a2SToomas Soome #define Z_DEFAULT_STRATEGY 0 201ab9e68a2SToomas Soome /* compression strategy; see deflateInit2() below for details */ 202ab9e68a2SToomas Soome 203ab9e68a2SToomas Soome #define Z_BINARY 0 204ab9e68a2SToomas Soome #define Z_TEXT 1 205ab9e68a2SToomas Soome #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 206ab9e68a2SToomas Soome #define Z_UNKNOWN 2 207ab9e68a2SToomas Soome /* Possible values of the data_type field for deflate() */ 208ab9e68a2SToomas Soome 209ab9e68a2SToomas Soome #define Z_DEFLATED 8 210ab9e68a2SToomas Soome /* The deflate compression method (the only one supported in this version) */ 211ab9e68a2SToomas Soome 212ab9e68a2SToomas Soome #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 213ab9e68a2SToomas Soome 214ab9e68a2SToomas Soome #define zlib_version zlibVersion() 215ab9e68a2SToomas Soome /* for compatibility with versions < 1.0.2 */ 216ab9e68a2SToomas Soome 217ab9e68a2SToomas Soome 218ab9e68a2SToomas Soome /* basic functions */ 219ab9e68a2SToomas Soome 220ab9e68a2SToomas Soome ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 221ab9e68a2SToomas Soome /* The application can compare zlibVersion and ZLIB_VERSION for consistency. 222ab9e68a2SToomas Soome If the first character differs, the library code actually used is not 223ab9e68a2SToomas Soome compatible with the zlib.h header file used by the application. This check 224ab9e68a2SToomas Soome is automatically made by deflateInit and inflateInit. 225ab9e68a2SToomas Soome */ 226ab9e68a2SToomas Soome 227ab9e68a2SToomas Soome /* 228ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 229ab9e68a2SToomas Soome 230ab9e68a2SToomas Soome Initializes the internal stream state for compression. The fields 231ab9e68a2SToomas Soome zalloc, zfree and opaque must be initialized before by the caller. If 232ab9e68a2SToomas Soome zalloc and zfree are set to Z_NULL, deflateInit updates them to use default 233ab9e68a2SToomas Soome allocation functions. 234ab9e68a2SToomas Soome 235ab9e68a2SToomas Soome The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 236ab9e68a2SToomas Soome 1 gives best speed, 9 gives best compression, 0 gives no compression at all 237ab9e68a2SToomas Soome (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION 238ab9e68a2SToomas Soome requests a default compromise between speed and compression (currently 239ab9e68a2SToomas Soome equivalent to level 6). 240ab9e68a2SToomas Soome 241ab9e68a2SToomas Soome deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 242ab9e68a2SToomas Soome memory, Z_STREAM_ERROR if level is not a valid compression level, or 243ab9e68a2SToomas Soome Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 244ab9e68a2SToomas Soome with the version assumed by the caller (ZLIB_VERSION). msg is set to null 245ab9e68a2SToomas Soome if there is no error message. deflateInit does not perform any compression: 246ab9e68a2SToomas Soome this will be done by deflate(). 247ab9e68a2SToomas Soome */ 248ab9e68a2SToomas Soome 249ab9e68a2SToomas Soome 250ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 251ab9e68a2SToomas Soome /* 252ab9e68a2SToomas Soome deflate compresses as much data as possible, and stops when the input 253ab9e68a2SToomas Soome buffer becomes empty or the output buffer becomes full. It may introduce 254ab9e68a2SToomas Soome some output latency (reading input without producing any output) except when 255ab9e68a2SToomas Soome forced to flush. 256ab9e68a2SToomas Soome 257ab9e68a2SToomas Soome The detailed semantics are as follows. deflate performs one or both of the 258ab9e68a2SToomas Soome following actions: 259ab9e68a2SToomas Soome 260ab9e68a2SToomas Soome - Compress more input starting at next_in and update next_in and avail_in 261ab9e68a2SToomas Soome accordingly. If not all input can be processed (because there is not 262ab9e68a2SToomas Soome enough room in the output buffer), next_in and avail_in are updated and 263ab9e68a2SToomas Soome processing will resume at this point for the next call of deflate(). 264ab9e68a2SToomas Soome 265ab9e68a2SToomas Soome - Generate more output starting at next_out and update next_out and avail_out 266ab9e68a2SToomas Soome accordingly. This action is forced if the parameter flush is non zero. 267ab9e68a2SToomas Soome Forcing flush frequently degrades the compression ratio, so this parameter 268ab9e68a2SToomas Soome should be set only when necessary. Some output may be provided even if 269ab9e68a2SToomas Soome flush is zero. 270ab9e68a2SToomas Soome 271ab9e68a2SToomas Soome Before the call of deflate(), the application should ensure that at least 272ab9e68a2SToomas Soome one of the actions is possible, by providing more input and/or consuming more 273ab9e68a2SToomas Soome output, and updating avail_in or avail_out accordingly; avail_out should 274ab9e68a2SToomas Soome never be zero before the call. The application can consume the compressed 275ab9e68a2SToomas Soome output when it wants, for example when the output buffer is full (avail_out 276ab9e68a2SToomas Soome == 0), or after each call of deflate(). If deflate returns Z_OK and with 277ab9e68a2SToomas Soome zero avail_out, it must be called again after making room in the output 278ab9e68a2SToomas Soome buffer because there might be more output pending. See deflatePending(), 279ab9e68a2SToomas Soome which can be used if desired to determine whether or not there is more ouput 280ab9e68a2SToomas Soome in that case. 281ab9e68a2SToomas Soome 282ab9e68a2SToomas Soome Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 283ab9e68a2SToomas Soome decide how much data to accumulate before producing output, in order to 284ab9e68a2SToomas Soome maximize compression. 285ab9e68a2SToomas Soome 286ab9e68a2SToomas Soome If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 287ab9e68a2SToomas Soome flushed to the output buffer and the output is aligned on a byte boundary, so 288ab9e68a2SToomas Soome that the decompressor can get all input data available so far. (In 289ab9e68a2SToomas Soome particular avail_in is zero after the call if enough output space has been 290ab9e68a2SToomas Soome provided before the call.) Flushing may degrade compression for some 291ab9e68a2SToomas Soome compression algorithms and so it should be used only when necessary. This 292ab9e68a2SToomas Soome completes the current deflate block and follows it with an empty stored block 293ab9e68a2SToomas Soome that is three bits plus filler bits to the next byte, followed by four bytes 294ab9e68a2SToomas Soome (00 00 ff ff). 295ab9e68a2SToomas Soome 296ab9e68a2SToomas Soome If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the 297ab9e68a2SToomas Soome output buffer, but the output is not aligned to a byte boundary. All of the 298ab9e68a2SToomas Soome input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. 299ab9e68a2SToomas Soome This completes the current deflate block and follows it with an empty fixed 300ab9e68a2SToomas Soome codes block that is 10 bits long. This assures that enough bytes are output 301ab9e68a2SToomas Soome in order for the decompressor to finish the block before the empty fixed 302ab9e68a2SToomas Soome codes block. 303ab9e68a2SToomas Soome 304ab9e68a2SToomas Soome If flush is set to Z_BLOCK, a deflate block is completed and emitted, as 305ab9e68a2SToomas Soome for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to 306ab9e68a2SToomas Soome seven bits of the current block are held to be written as the next byte after 307ab9e68a2SToomas Soome the next deflate block is completed. In this case, the decompressor may not 308ab9e68a2SToomas Soome be provided enough bits at this point in order to complete decompression of 309ab9e68a2SToomas Soome the data provided so far to the compressor. It may need to wait for the next 310ab9e68a2SToomas Soome block to be emitted. This is for advanced applications that need to control 311ab9e68a2SToomas Soome the emission of deflate blocks. 312ab9e68a2SToomas Soome 313ab9e68a2SToomas Soome If flush is set to Z_FULL_FLUSH, all output is flushed as with 314ab9e68a2SToomas Soome Z_SYNC_FLUSH, and the compression state is reset so that decompression can 315ab9e68a2SToomas Soome restart from this point if previous compressed data has been damaged or if 316ab9e68a2SToomas Soome random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 317ab9e68a2SToomas Soome compression. 318ab9e68a2SToomas Soome 319ab9e68a2SToomas Soome If deflate returns with avail_out == 0, this function must be called again 320ab9e68a2SToomas Soome with the same value of the flush parameter and more output space (updated 321ab9e68a2SToomas Soome avail_out), until the flush is complete (deflate returns with non-zero 322ab9e68a2SToomas Soome avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 323ab9e68a2SToomas Soome avail_out is greater than six to avoid repeated flush markers due to 324ab9e68a2SToomas Soome avail_out == 0 on return. 325ab9e68a2SToomas Soome 326ab9e68a2SToomas Soome If the parameter flush is set to Z_FINISH, pending input is processed, 327ab9e68a2SToomas Soome pending output is flushed and deflate returns with Z_STREAM_END if there was 328ab9e68a2SToomas Soome enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this 329ab9e68a2SToomas Soome function must be called again with Z_FINISH and more output space (updated 330ab9e68a2SToomas Soome avail_out) but no more input data, until it returns with Z_STREAM_END or an 331ab9e68a2SToomas Soome error. After deflate has returned Z_STREAM_END, the only possible operations 332ab9e68a2SToomas Soome on the stream are deflateReset or deflateEnd. 333ab9e68a2SToomas Soome 334ab9e68a2SToomas Soome Z_FINISH can be used in the first deflate call after deflateInit if all the 335ab9e68a2SToomas Soome compression is to be done in a single step. In order to complete in one 336ab9e68a2SToomas Soome call, avail_out must be at least the value returned by deflateBound (see 337ab9e68a2SToomas Soome below). Then deflate is guaranteed to return Z_STREAM_END. If not enough 338ab9e68a2SToomas Soome output space is provided, deflate will not return Z_STREAM_END, and it must 339ab9e68a2SToomas Soome be called again as described above. 340ab9e68a2SToomas Soome 341ab9e68a2SToomas Soome deflate() sets strm->adler to the Adler-32 checksum of all input read 342ab9e68a2SToomas Soome so far (that is, total_in bytes). If a gzip stream is being generated, then 343ab9e68a2SToomas Soome strm->adler will be the CRC-32 checksum of the input read so far. (See 344ab9e68a2SToomas Soome deflateInit2 below.) 345ab9e68a2SToomas Soome 346ab9e68a2SToomas Soome deflate() may update strm->data_type if it can make a good guess about 347ab9e68a2SToomas Soome the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is 348ab9e68a2SToomas Soome considered binary. This field is only for information purposes and does not 349ab9e68a2SToomas Soome affect the compression algorithm in any manner. 350ab9e68a2SToomas Soome 351ab9e68a2SToomas Soome deflate() returns Z_OK if some progress has been made (more input 352ab9e68a2SToomas Soome processed or more output produced), Z_STREAM_END if all input has been 353ab9e68a2SToomas Soome consumed and all output has been produced (only when flush is set to 354ab9e68a2SToomas Soome Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 355ab9e68a2SToomas Soome if next_in or next_out was Z_NULL or the state was inadvertently written over 356ab9e68a2SToomas Soome by the application), or Z_BUF_ERROR if no progress is possible (for example 357ab9e68a2SToomas Soome avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and 358ab9e68a2SToomas Soome deflate() can be called again with more input and more output space to 359ab9e68a2SToomas Soome continue compressing. 360ab9e68a2SToomas Soome */ 361ab9e68a2SToomas Soome 362ab9e68a2SToomas Soome 363ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 364ab9e68a2SToomas Soome /* 365ab9e68a2SToomas Soome All dynamically allocated data structures for this stream are freed. 366ab9e68a2SToomas Soome This function discards any unprocessed input and does not flush any pending 367ab9e68a2SToomas Soome output. 368ab9e68a2SToomas Soome 369ab9e68a2SToomas Soome deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 370ab9e68a2SToomas Soome stream state was inconsistent, Z_DATA_ERROR if the stream was freed 371ab9e68a2SToomas Soome prematurely (some input or output was discarded). In the error case, msg 372ab9e68a2SToomas Soome may be set but then points to a static string (which must not be 373ab9e68a2SToomas Soome deallocated). 374ab9e68a2SToomas Soome */ 375ab9e68a2SToomas Soome 376ab9e68a2SToomas Soome 377ab9e68a2SToomas Soome /* 378ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 379ab9e68a2SToomas Soome 380ab9e68a2SToomas Soome Initializes the internal stream state for decompression. The fields 381ab9e68a2SToomas Soome next_in, avail_in, zalloc, zfree and opaque must be initialized before by 382ab9e68a2SToomas Soome the caller. In the current version of inflate, the provided input is not 383ab9e68a2SToomas Soome read or consumed. The allocation of a sliding window will be deferred to 384ab9e68a2SToomas Soome the first call of inflate (if the decompression does not complete on the 385ab9e68a2SToomas Soome first call). If zalloc and zfree are set to Z_NULL, inflateInit updates 386ab9e68a2SToomas Soome them to use default allocation functions. 387ab9e68a2SToomas Soome 388ab9e68a2SToomas Soome inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 389ab9e68a2SToomas Soome memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 390ab9e68a2SToomas Soome version assumed by the caller, or Z_STREAM_ERROR if the parameters are 391ab9e68a2SToomas Soome invalid, such as a null pointer to the structure. msg is set to null if 392ab9e68a2SToomas Soome there is no error message. inflateInit does not perform any decompression. 393ab9e68a2SToomas Soome Actual decompression will be done by inflate(). So next_in, and avail_in, 394ab9e68a2SToomas Soome next_out, and avail_out are unused and unchanged. The current 395ab9e68a2SToomas Soome implementation of inflateInit() does not process any header information -- 396ab9e68a2SToomas Soome that is deferred until inflate() is called. 397ab9e68a2SToomas Soome */ 398ab9e68a2SToomas Soome 399ab9e68a2SToomas Soome 400ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 401ab9e68a2SToomas Soome /* 402ab9e68a2SToomas Soome inflate decompresses as much data as possible, and stops when the input 403ab9e68a2SToomas Soome buffer becomes empty or the output buffer becomes full. It may introduce 404ab9e68a2SToomas Soome some output latency (reading input without producing any output) except when 405ab9e68a2SToomas Soome forced to flush. 406ab9e68a2SToomas Soome 407ab9e68a2SToomas Soome The detailed semantics are as follows. inflate performs one or both of the 408ab9e68a2SToomas Soome following actions: 409ab9e68a2SToomas Soome 410ab9e68a2SToomas Soome - Decompress more input starting at next_in and update next_in and avail_in 411ab9e68a2SToomas Soome accordingly. If not all input can be processed (because there is not 412ab9e68a2SToomas Soome enough room in the output buffer), then next_in and avail_in are updated 413ab9e68a2SToomas Soome accordingly, and processing will resume at this point for the next call of 414ab9e68a2SToomas Soome inflate(). 415ab9e68a2SToomas Soome 416ab9e68a2SToomas Soome - Generate more output starting at next_out and update next_out and avail_out 417ab9e68a2SToomas Soome accordingly. inflate() provides as much output as possible, until there is 418ab9e68a2SToomas Soome no more input data or no more space in the output buffer (see below about 419ab9e68a2SToomas Soome the flush parameter). 420ab9e68a2SToomas Soome 421ab9e68a2SToomas Soome Before the call of inflate(), the application should ensure that at least 422ab9e68a2SToomas Soome one of the actions is possible, by providing more input and/or consuming more 423ab9e68a2SToomas Soome output, and updating the next_* and avail_* values accordingly. If the 424ab9e68a2SToomas Soome caller of inflate() does not provide both available input and available 425ab9e68a2SToomas Soome output space, it is possible that there will be no progress made. The 426ab9e68a2SToomas Soome application can consume the uncompressed output when it wants, for example 427ab9e68a2SToomas Soome when the output buffer is full (avail_out == 0), or after each call of 428ab9e68a2SToomas Soome inflate(). If inflate returns Z_OK and with zero avail_out, it must be 429ab9e68a2SToomas Soome called again after making room in the output buffer because there might be 430ab9e68a2SToomas Soome more output pending. 431ab9e68a2SToomas Soome 432ab9e68a2SToomas Soome The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, 433ab9e68a2SToomas Soome Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much 434ab9e68a2SToomas Soome output as possible to the output buffer. Z_BLOCK requests that inflate() 435ab9e68a2SToomas Soome stop if and when it gets to the next deflate block boundary. When decoding 436ab9e68a2SToomas Soome the zlib or gzip format, this will cause inflate() to return immediately 437ab9e68a2SToomas Soome after the header and before the first block. When doing a raw inflate, 438ab9e68a2SToomas Soome inflate() will go ahead and process the first block, and will return when it 439ab9e68a2SToomas Soome gets to the end of that block, or when it runs out of data. 440ab9e68a2SToomas Soome 441ab9e68a2SToomas Soome The Z_BLOCK option assists in appending to or combining deflate streams. 442ab9e68a2SToomas Soome To assist in this, on return inflate() always sets strm->data_type to the 443ab9e68a2SToomas Soome number of unused bits in the last byte taken from strm->next_in, plus 64 if 444ab9e68a2SToomas Soome inflate() is currently decoding the last block in the deflate stream, plus 445ab9e68a2SToomas Soome 128 if inflate() returned immediately after decoding an end-of-block code or 446ab9e68a2SToomas Soome decoding the complete header up to just before the first byte of the deflate 447ab9e68a2SToomas Soome stream. The end-of-block will not be indicated until all of the uncompressed 448ab9e68a2SToomas Soome data from that block has been written to strm->next_out. The number of 449ab9e68a2SToomas Soome unused bits may in general be greater than seven, except when bit 7 of 450ab9e68a2SToomas Soome data_type is set, in which case the number of unused bits will be less than 451ab9e68a2SToomas Soome eight. data_type is set as noted here every time inflate() returns for all 452ab9e68a2SToomas Soome flush options, and so can be used to determine the amount of currently 453ab9e68a2SToomas Soome consumed input in bits. 454ab9e68a2SToomas Soome 455ab9e68a2SToomas Soome The Z_TREES option behaves as Z_BLOCK does, but it also returns when the 456ab9e68a2SToomas Soome end of each deflate block header is reached, before any actual data in that 457ab9e68a2SToomas Soome block is decoded. This allows the caller to determine the length of the 458ab9e68a2SToomas Soome deflate block header for later use in random access within a deflate block. 459ab9e68a2SToomas Soome 256 is added to the value of strm->data_type when inflate() returns 460ab9e68a2SToomas Soome immediately after reaching the end of the deflate block header. 461ab9e68a2SToomas Soome 462ab9e68a2SToomas Soome inflate() should normally be called until it returns Z_STREAM_END or an 463ab9e68a2SToomas Soome error. However if all decompression is to be performed in a single step (a 464ab9e68a2SToomas Soome single call of inflate), the parameter flush should be set to Z_FINISH. In 465ab9e68a2SToomas Soome this case all pending input is processed and all pending output is flushed; 466ab9e68a2SToomas Soome avail_out must be large enough to hold all of the uncompressed data for the 467ab9e68a2SToomas Soome operation to complete. (The size of the uncompressed data may have been 468ab9e68a2SToomas Soome saved by the compressor for this purpose.) The use of Z_FINISH is not 469ab9e68a2SToomas Soome required to perform an inflation in one step. However it may be used to 470ab9e68a2SToomas Soome inform inflate that a faster approach can be used for the single inflate() 471ab9e68a2SToomas Soome call. Z_FINISH also informs inflate to not maintain a sliding window if the 472ab9e68a2SToomas Soome stream completes, which reduces inflate's memory footprint. If the stream 473ab9e68a2SToomas Soome does not complete, either because not all of the stream is provided or not 474ab9e68a2SToomas Soome enough output space is provided, then a sliding window will be allocated and 475ab9e68a2SToomas Soome inflate() can be called again to continue the operation as if Z_NO_FLUSH had 476ab9e68a2SToomas Soome been used. 477ab9e68a2SToomas Soome 478ab9e68a2SToomas Soome In this implementation, inflate() always flushes as much output as 479ab9e68a2SToomas Soome possible to the output buffer, and always uses the faster approach on the 480ab9e68a2SToomas Soome first call. So the effects of the flush parameter in this implementation are 481ab9e68a2SToomas Soome on the return value of inflate() as noted below, when inflate() returns early 482ab9e68a2SToomas Soome when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of 483ab9e68a2SToomas Soome memory for a sliding window when Z_FINISH is used. 484ab9e68a2SToomas Soome 485ab9e68a2SToomas Soome If a preset dictionary is needed after this call (see inflateSetDictionary 486ab9e68a2SToomas Soome below), inflate sets strm->adler to the Adler-32 checksum of the dictionary 487ab9e68a2SToomas Soome chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 488ab9e68a2SToomas Soome strm->adler to the Adler-32 checksum of all output produced so far (that is, 489ab9e68a2SToomas Soome total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 490ab9e68a2SToomas Soome below. At the end of the stream, inflate() checks that its computed Adler-32 491ab9e68a2SToomas Soome checksum is equal to that saved by the compressor and returns Z_STREAM_END 492ab9e68a2SToomas Soome only if the checksum is correct. 493ab9e68a2SToomas Soome 494ab9e68a2SToomas Soome inflate() can decompress and check either zlib-wrapped or gzip-wrapped 495ab9e68a2SToomas Soome deflate data. The header type is detected automatically, if requested when 496ab9e68a2SToomas Soome initializing with inflateInit2(). Any information contained in the gzip 497ab9e68a2SToomas Soome header is not retained unless inflateGetHeader() is used. When processing 498ab9e68a2SToomas Soome gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output 499ab9e68a2SToomas Soome produced so far. The CRC-32 is checked against the gzip trailer, as is the 500ab9e68a2SToomas Soome uncompressed length, modulo 2^32. 501ab9e68a2SToomas Soome 502ab9e68a2SToomas Soome inflate() returns Z_OK if some progress has been made (more input processed 503ab9e68a2SToomas Soome or more output produced), Z_STREAM_END if the end of the compressed data has 504ab9e68a2SToomas Soome been reached and all uncompressed output has been produced, Z_NEED_DICT if a 505ab9e68a2SToomas Soome preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 506ab9e68a2SToomas Soome corrupted (input stream not conforming to the zlib format or incorrect check 507ab9e68a2SToomas Soome value, in which case strm->msg points to a string with a more specific 508ab9e68a2SToomas Soome error), Z_STREAM_ERROR if the stream structure was inconsistent (for example 509ab9e68a2SToomas Soome next_in or next_out was Z_NULL, or the state was inadvertently written over 510ab9e68a2SToomas Soome by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR 511ab9e68a2SToomas Soome if no progress was possible or if there was not enough room in the output 512ab9e68a2SToomas Soome buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 513ab9e68a2SToomas Soome inflate() can be called again with more input and more output space to 514ab9e68a2SToomas Soome continue decompressing. If Z_DATA_ERROR is returned, the application may 515ab9e68a2SToomas Soome then call inflateSync() to look for a good compression block if a partial 516ab9e68a2SToomas Soome recovery of the data is to be attempted. 517ab9e68a2SToomas Soome */ 518ab9e68a2SToomas Soome 519ab9e68a2SToomas Soome 520ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 521ab9e68a2SToomas Soome /* 522ab9e68a2SToomas Soome All dynamically allocated data structures for this stream are freed. 523ab9e68a2SToomas Soome This function discards any unprocessed input and does not flush any pending 524ab9e68a2SToomas Soome output. 525ab9e68a2SToomas Soome 526ab9e68a2SToomas Soome inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state 527ab9e68a2SToomas Soome was inconsistent. 528ab9e68a2SToomas Soome */ 529ab9e68a2SToomas Soome 530ab9e68a2SToomas Soome 531ab9e68a2SToomas Soome /* Advanced functions */ 532ab9e68a2SToomas Soome 533ab9e68a2SToomas Soome /* 534ab9e68a2SToomas Soome The following functions are needed only in some special applications. 535ab9e68a2SToomas Soome */ 536ab9e68a2SToomas Soome 537ab9e68a2SToomas Soome /* 538ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 539ab9e68a2SToomas Soome int level, 540ab9e68a2SToomas Soome int method, 541ab9e68a2SToomas Soome int windowBits, 542ab9e68a2SToomas Soome int memLevel, 543ab9e68a2SToomas Soome int strategy)); 544ab9e68a2SToomas Soome 545ab9e68a2SToomas Soome This is another version of deflateInit with more compression options. The 546*64c3d159SToomas Soome fields zalloc, zfree and opaque must be initialized before by the caller. 547ab9e68a2SToomas Soome 548ab9e68a2SToomas Soome The method parameter is the compression method. It must be Z_DEFLATED in 549ab9e68a2SToomas Soome this version of the library. 550ab9e68a2SToomas Soome 551ab9e68a2SToomas Soome The windowBits parameter is the base two logarithm of the window size 552ab9e68a2SToomas Soome (the size of the history buffer). It should be in the range 8..15 for this 553ab9e68a2SToomas Soome version of the library. Larger values of this parameter result in better 554ab9e68a2SToomas Soome compression at the expense of memory usage. The default value is 15 if 555ab9e68a2SToomas Soome deflateInit is used instead. 556ab9e68a2SToomas Soome 557ab9e68a2SToomas Soome For the current implementation of deflate(), a windowBits value of 8 (a 558ab9e68a2SToomas Soome window size of 256 bytes) is not supported. As a result, a request for 8 559ab9e68a2SToomas Soome will result in 9 (a 512-byte window). In that case, providing 8 to 560ab9e68a2SToomas Soome inflateInit2() will result in an error when the zlib header with 9 is 561ab9e68a2SToomas Soome checked against the initialization of inflate(). The remedy is to not use 8 562ab9e68a2SToomas Soome with deflateInit2() with this initialization, or at least in that case use 9 563ab9e68a2SToomas Soome with inflateInit2(). 564ab9e68a2SToomas Soome 565ab9e68a2SToomas Soome windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 566ab9e68a2SToomas Soome determines the window size. deflate() will then generate raw deflate data 567ab9e68a2SToomas Soome with no zlib header or trailer, and will not compute a check value. 568ab9e68a2SToomas Soome 569ab9e68a2SToomas Soome windowBits can also be greater than 15 for optional gzip encoding. Add 570ab9e68a2SToomas Soome 16 to windowBits to write a simple gzip header and trailer around the 571ab9e68a2SToomas Soome compressed data instead of a zlib wrapper. The gzip header will have no 572ab9e68a2SToomas Soome file name, no extra data, no comment, no modification time (set to zero), no 573ab9e68a2SToomas Soome header crc, and the operating system will be set to the appropriate value, 574ab9e68a2SToomas Soome if the operating system was determined at compile time. If a gzip stream is 575ab9e68a2SToomas Soome being written, strm->adler is a CRC-32 instead of an Adler-32. 576ab9e68a2SToomas Soome 577ab9e68a2SToomas Soome For raw deflate or gzip encoding, a request for a 256-byte window is 578ab9e68a2SToomas Soome rejected as invalid, since only the zlib header provides a means of 579ab9e68a2SToomas Soome transmitting the window size to the decompressor. 580ab9e68a2SToomas Soome 581ab9e68a2SToomas Soome The memLevel parameter specifies how much memory should be allocated 582ab9e68a2SToomas Soome for the internal compression state. memLevel=1 uses minimum memory but is 583ab9e68a2SToomas Soome slow and reduces compression ratio; memLevel=9 uses maximum memory for 584ab9e68a2SToomas Soome optimal speed. The default value is 8. See zconf.h for total memory usage 585ab9e68a2SToomas Soome as a function of windowBits and memLevel. 586ab9e68a2SToomas Soome 587ab9e68a2SToomas Soome The strategy parameter is used to tune the compression algorithm. Use the 588ab9e68a2SToomas Soome value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 589ab9e68a2SToomas Soome filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 590ab9e68a2SToomas Soome string match), or Z_RLE to limit match distances to one (run-length 591ab9e68a2SToomas Soome encoding). Filtered data consists mostly of small values with a somewhat 592ab9e68a2SToomas Soome random distribution. In this case, the compression algorithm is tuned to 593ab9e68a2SToomas Soome compress them better. The effect of Z_FILTERED is to force more Huffman 594ab9e68a2SToomas Soome coding and less string matching; it is somewhat intermediate between 595ab9e68a2SToomas Soome Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as 596ab9e68a2SToomas Soome fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The 597ab9e68a2SToomas Soome strategy parameter only affects the compression ratio but not the 598ab9e68a2SToomas Soome correctness of the compressed output even if it is not set appropriately. 599ab9e68a2SToomas Soome Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler 600ab9e68a2SToomas Soome decoder for special applications. 601ab9e68a2SToomas Soome 602ab9e68a2SToomas Soome deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 603ab9e68a2SToomas Soome memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid 604ab9e68a2SToomas Soome method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is 605ab9e68a2SToomas Soome incompatible with the version assumed by the caller (ZLIB_VERSION). msg is 606ab9e68a2SToomas Soome set to null if there is no error message. deflateInit2 does not perform any 607ab9e68a2SToomas Soome compression: this will be done by deflate(). 608ab9e68a2SToomas Soome */ 609ab9e68a2SToomas Soome 610ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 611ab9e68a2SToomas Soome const Bytef *dictionary, 612ab9e68a2SToomas Soome uInt dictLength)); 613ab9e68a2SToomas Soome /* 614ab9e68a2SToomas Soome Initializes the compression dictionary from the given byte sequence 615ab9e68a2SToomas Soome without producing any compressed output. When using the zlib format, this 616ab9e68a2SToomas Soome function must be called immediately after deflateInit, deflateInit2 or 617ab9e68a2SToomas Soome deflateReset, and before any call of deflate. When doing raw deflate, this 618ab9e68a2SToomas Soome function must be called either before any call of deflate, or immediately 619ab9e68a2SToomas Soome after the completion of a deflate block, i.e. after all input has been 620ab9e68a2SToomas Soome consumed and all output has been delivered when using any of the flush 621ab9e68a2SToomas Soome options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The 622ab9e68a2SToomas Soome compressor and decompressor must use exactly the same dictionary (see 623ab9e68a2SToomas Soome inflateSetDictionary). 624ab9e68a2SToomas Soome 625ab9e68a2SToomas Soome The dictionary should consist of strings (byte sequences) that are likely 626ab9e68a2SToomas Soome to be encountered later in the data to be compressed, with the most commonly 627ab9e68a2SToomas Soome used strings preferably put towards the end of the dictionary. Using a 628ab9e68a2SToomas Soome dictionary is most useful when the data to be compressed is short and can be 629ab9e68a2SToomas Soome predicted with good accuracy; the data can then be compressed better than 630ab9e68a2SToomas Soome with the default empty dictionary. 631ab9e68a2SToomas Soome 632ab9e68a2SToomas Soome Depending on the size of the compression data structures selected by 633ab9e68a2SToomas Soome deflateInit or deflateInit2, a part of the dictionary may in effect be 634ab9e68a2SToomas Soome discarded, for example if the dictionary is larger than the window size 635ab9e68a2SToomas Soome provided in deflateInit or deflateInit2. Thus the strings most likely to be 636ab9e68a2SToomas Soome useful should be put at the end of the dictionary, not at the front. In 637ab9e68a2SToomas Soome addition, the current implementation of deflate will use at most the window 638ab9e68a2SToomas Soome size minus 262 bytes of the provided dictionary. 639ab9e68a2SToomas Soome 640ab9e68a2SToomas Soome Upon return of this function, strm->adler is set to the Adler-32 value 641ab9e68a2SToomas Soome of the dictionary; the decompressor may later use this value to determine 642ab9e68a2SToomas Soome which dictionary has been used by the compressor. (The Adler-32 value 643ab9e68a2SToomas Soome applies to the whole dictionary even if only a subset of the dictionary is 644ab9e68a2SToomas Soome actually used by the compressor.) If a raw deflate was requested, then the 645ab9e68a2SToomas Soome Adler-32 value is not computed and strm->adler is not set. 646ab9e68a2SToomas Soome 647ab9e68a2SToomas Soome deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 648ab9e68a2SToomas Soome parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 649ab9e68a2SToomas Soome inconsistent (for example if deflate has already been called for this stream 650ab9e68a2SToomas Soome or if not at a block boundary for raw deflate). deflateSetDictionary does 651ab9e68a2SToomas Soome not perform any compression: this will be done by deflate(). 652ab9e68a2SToomas Soome */ 653ab9e68a2SToomas Soome 654ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, 655ab9e68a2SToomas Soome Bytef *dictionary, 656ab9e68a2SToomas Soome uInt *dictLength)); 657ab9e68a2SToomas Soome /* 658ab9e68a2SToomas Soome Returns the sliding dictionary being maintained by deflate. dictLength is 659ab9e68a2SToomas Soome set to the number of bytes in the dictionary, and that many bytes are copied 660ab9e68a2SToomas Soome to dictionary. dictionary must have enough space, where 32768 bytes is 661ab9e68a2SToomas Soome always enough. If deflateGetDictionary() is called with dictionary equal to 662ab9e68a2SToomas Soome Z_NULL, then only the dictionary length is returned, and nothing is copied. 663ab9e68a2SToomas Soome Similary, if dictLength is Z_NULL, then it is not set. 664ab9e68a2SToomas Soome 665ab9e68a2SToomas Soome deflateGetDictionary() may return a length less than the window size, even 666ab9e68a2SToomas Soome when more than the window size in input has been provided. It may return up 667ab9e68a2SToomas Soome to 258 bytes less in that case, due to how zlib's implementation of deflate 668ab9e68a2SToomas Soome manages the sliding window and lookahead for matches, where matches can be 669ab9e68a2SToomas Soome up to 258 bytes long. If the application needs the last window-size bytes of 670ab9e68a2SToomas Soome input, then that would need to be saved by the application outside of zlib. 671ab9e68a2SToomas Soome 672ab9e68a2SToomas Soome deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the 673ab9e68a2SToomas Soome stream state is inconsistent. 674ab9e68a2SToomas Soome */ 675ab9e68a2SToomas Soome 676ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 677ab9e68a2SToomas Soome z_streamp source)); 678ab9e68a2SToomas Soome /* 679ab9e68a2SToomas Soome Sets the destination stream as a complete copy of the source stream. 680ab9e68a2SToomas Soome 681ab9e68a2SToomas Soome This function can be useful when several compression strategies will be 682ab9e68a2SToomas Soome tried, for example when there are several ways of pre-processing the input 683ab9e68a2SToomas Soome data with a filter. The streams that will be discarded should then be freed 684ab9e68a2SToomas Soome by calling deflateEnd. Note that deflateCopy duplicates the internal 685ab9e68a2SToomas Soome compression state which can be quite large, so this strategy is slow and can 686ab9e68a2SToomas Soome consume lots of memory. 687ab9e68a2SToomas Soome 688ab9e68a2SToomas Soome deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 689ab9e68a2SToomas Soome enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 690ab9e68a2SToomas Soome (such as zalloc being Z_NULL). msg is left unchanged in both source and 691ab9e68a2SToomas Soome destination. 692ab9e68a2SToomas Soome */ 693ab9e68a2SToomas Soome 694ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 695ab9e68a2SToomas Soome /* 696ab9e68a2SToomas Soome This function is equivalent to deflateEnd followed by deflateInit, but 697ab9e68a2SToomas Soome does not free and reallocate the internal compression state. The stream 698ab9e68a2SToomas Soome will leave the compression level and any other attributes that may have been 699ab9e68a2SToomas Soome set unchanged. 700ab9e68a2SToomas Soome 701ab9e68a2SToomas Soome deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 702ab9e68a2SToomas Soome stream state was inconsistent (such as zalloc or state being Z_NULL). 703ab9e68a2SToomas Soome */ 704ab9e68a2SToomas Soome 705ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 706ab9e68a2SToomas Soome int level, 707ab9e68a2SToomas Soome int strategy)); 708ab9e68a2SToomas Soome /* 709ab9e68a2SToomas Soome Dynamically update the compression level and compression strategy. The 710ab9e68a2SToomas Soome interpretation of level and strategy is as in deflateInit2(). This can be 711ab9e68a2SToomas Soome used to switch between compression and straight copy of the input data, or 712ab9e68a2SToomas Soome to switch to a different kind of input data requiring a different strategy. 713ab9e68a2SToomas Soome If the compression approach (which is a function of the level) or the 714*64c3d159SToomas Soome strategy is changed, and if there have been any deflate() calls since the 715*64c3d159SToomas Soome state was initialized or reset, then the input available so far is 716*64c3d159SToomas Soome compressed with the old level and strategy using deflate(strm, Z_BLOCK). 717*64c3d159SToomas Soome There are three approaches for the compression levels 0, 1..3, and 4..9 718*64c3d159SToomas Soome respectively. The new level and strategy will take effect at the next call 719*64c3d159SToomas Soome of deflate(). 720ab9e68a2SToomas Soome 721ab9e68a2SToomas Soome If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does 722ab9e68a2SToomas Soome not have enough output space to complete, then the parameter change will not 723ab9e68a2SToomas Soome take effect. In this case, deflateParams() can be called again with the 724ab9e68a2SToomas Soome same parameters and more output space to try again. 725ab9e68a2SToomas Soome 726ab9e68a2SToomas Soome In order to assure a change in the parameters on the first try, the 727ab9e68a2SToomas Soome deflate stream should be flushed using deflate() with Z_BLOCK or other flush 728ab9e68a2SToomas Soome request until strm.avail_out is not zero, before calling deflateParams(). 729ab9e68a2SToomas Soome Then no more input data should be provided before the deflateParams() call. 730ab9e68a2SToomas Soome If this is done, the old level and strategy will be applied to the data 731ab9e68a2SToomas Soome compressed before deflateParams(), and the new level and strategy will be 732ab9e68a2SToomas Soome applied to the the data compressed after deflateParams(). 733ab9e68a2SToomas Soome 734ab9e68a2SToomas Soome deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream 735ab9e68a2SToomas Soome state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if 736ab9e68a2SToomas Soome there was not enough output space to complete the compression of the 737ab9e68a2SToomas Soome available input data before a change in the strategy or approach. Note that 738ab9e68a2SToomas Soome in the case of a Z_BUF_ERROR, the parameters are not changed. A return 739ab9e68a2SToomas Soome value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be 740ab9e68a2SToomas Soome retried with more output space. 741ab9e68a2SToomas Soome */ 742ab9e68a2SToomas Soome 743ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 744ab9e68a2SToomas Soome int good_length, 745ab9e68a2SToomas Soome int max_lazy, 746ab9e68a2SToomas Soome int nice_length, 747ab9e68a2SToomas Soome int max_chain)); 748ab9e68a2SToomas Soome /* 749ab9e68a2SToomas Soome Fine tune deflate's internal compression parameters. This should only be 750ab9e68a2SToomas Soome used by someone who understands the algorithm used by zlib's deflate for 751ab9e68a2SToomas Soome searching for the best matching string, and even then only by the most 752ab9e68a2SToomas Soome fanatic optimizer trying to squeeze out the last compressed bit for their 753ab9e68a2SToomas Soome specific input data. Read the deflate.c source code for the meaning of the 754ab9e68a2SToomas Soome max_lazy, good_length, nice_length, and max_chain parameters. 755ab9e68a2SToomas Soome 756ab9e68a2SToomas Soome deflateTune() can be called after deflateInit() or deflateInit2(), and 757ab9e68a2SToomas Soome returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 758ab9e68a2SToomas Soome */ 759ab9e68a2SToomas Soome 760ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 761ab9e68a2SToomas Soome uLong sourceLen)); 762ab9e68a2SToomas Soome /* 763ab9e68a2SToomas Soome deflateBound() returns an upper bound on the compressed size after 764ab9e68a2SToomas Soome deflation of sourceLen bytes. It must be called after deflateInit() or 765ab9e68a2SToomas Soome deflateInit2(), and after deflateSetHeader(), if used. This would be used 766ab9e68a2SToomas Soome to allocate an output buffer for deflation in a single pass, and so would be 767ab9e68a2SToomas Soome called before deflate(). If that first deflate() call is provided the 768ab9e68a2SToomas Soome sourceLen input bytes, an output buffer allocated to the size returned by 769ab9e68a2SToomas Soome deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed 770ab9e68a2SToomas Soome to return Z_STREAM_END. Note that it is possible for the compressed size to 771ab9e68a2SToomas Soome be larger than the value returned by deflateBound() if flush options other 772ab9e68a2SToomas Soome than Z_FINISH or Z_NO_FLUSH are used. 773ab9e68a2SToomas Soome */ 774ab9e68a2SToomas Soome 775ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, 776ab9e68a2SToomas Soome unsigned *pending, 777ab9e68a2SToomas Soome int *bits)); 778ab9e68a2SToomas Soome /* 779ab9e68a2SToomas Soome deflatePending() returns the number of bytes and bits of output that have 780ab9e68a2SToomas Soome been generated, but not yet provided in the available output. The bytes not 781ab9e68a2SToomas Soome provided would be due to the available output space having being consumed. 782ab9e68a2SToomas Soome The number of bits of output not provided are between 0 and 7, where they 783ab9e68a2SToomas Soome await more bits to join them in order to fill out a full byte. If pending 784ab9e68a2SToomas Soome or bits are Z_NULL, then those values are not set. 785ab9e68a2SToomas Soome 786ab9e68a2SToomas Soome deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source 787ab9e68a2SToomas Soome stream state was inconsistent. 788ab9e68a2SToomas Soome */ 789ab9e68a2SToomas Soome 790ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 791ab9e68a2SToomas Soome int bits, 792ab9e68a2SToomas Soome int value)); 793ab9e68a2SToomas Soome /* 794ab9e68a2SToomas Soome deflatePrime() inserts bits in the deflate output stream. The intent 795ab9e68a2SToomas Soome is that this function is used to start off the deflate output with the bits 796ab9e68a2SToomas Soome leftover from a previous deflate stream when appending to it. As such, this 797ab9e68a2SToomas Soome function can only be used for raw deflate, and must be used before the first 798ab9e68a2SToomas Soome deflate() call after a deflateInit2() or deflateReset(). bits must be less 799ab9e68a2SToomas Soome than or equal to 16, and that many of the least significant bits of value 800ab9e68a2SToomas Soome will be inserted in the output. 801ab9e68a2SToomas Soome 802ab9e68a2SToomas Soome deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough 803ab9e68a2SToomas Soome room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the 804ab9e68a2SToomas Soome source stream state was inconsistent. 805ab9e68a2SToomas Soome */ 806ab9e68a2SToomas Soome 807ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 808ab9e68a2SToomas Soome gz_headerp head)); 809ab9e68a2SToomas Soome /* 810ab9e68a2SToomas Soome deflateSetHeader() provides gzip header information for when a gzip 811ab9e68a2SToomas Soome stream is requested by deflateInit2(). deflateSetHeader() may be called 812ab9e68a2SToomas Soome after deflateInit2() or deflateReset() and before the first call of 813ab9e68a2SToomas Soome deflate(). The text, time, os, extra field, name, and comment information 814ab9e68a2SToomas Soome in the provided gz_header structure are written to the gzip header (xflag is 815ab9e68a2SToomas Soome ignored -- the extra flags are set according to the compression level). The 816ab9e68a2SToomas Soome caller must assure that, if not Z_NULL, name and comment are terminated with 817ab9e68a2SToomas Soome a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 818ab9e68a2SToomas Soome available there. If hcrc is true, a gzip header crc is included. Note that 819ab9e68a2SToomas Soome the current versions of the command-line version of gzip (up through version 820ab9e68a2SToomas Soome 1.3.x) do not support header crc's, and will report that it is a "multi-part 821ab9e68a2SToomas Soome gzip file" and give up. 822ab9e68a2SToomas Soome 823ab9e68a2SToomas Soome If deflateSetHeader is not used, the default gzip header has text false, 824ab9e68a2SToomas Soome the time set to zero, and os set to 255, with no extra, name, or comment 825ab9e68a2SToomas Soome fields. The gzip header is returned to the default state by deflateReset(). 826ab9e68a2SToomas Soome 827ab9e68a2SToomas Soome deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 828ab9e68a2SToomas Soome stream state was inconsistent. 829ab9e68a2SToomas Soome */ 830ab9e68a2SToomas Soome 831ab9e68a2SToomas Soome /* 832ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 833ab9e68a2SToomas Soome int windowBits)); 834ab9e68a2SToomas Soome 835ab9e68a2SToomas Soome This is another version of inflateInit with an extra parameter. The 836ab9e68a2SToomas Soome fields next_in, avail_in, zalloc, zfree and opaque must be initialized 837ab9e68a2SToomas Soome before by the caller. 838ab9e68a2SToomas Soome 839ab9e68a2SToomas Soome The windowBits parameter is the base two logarithm of the maximum window 840ab9e68a2SToomas Soome size (the size of the history buffer). It should be in the range 8..15 for 841ab9e68a2SToomas Soome this version of the library. The default value is 15 if inflateInit is used 842ab9e68a2SToomas Soome instead. windowBits must be greater than or equal to the windowBits value 843ab9e68a2SToomas Soome provided to deflateInit2() while compressing, or it must be equal to 15 if 844ab9e68a2SToomas Soome deflateInit2() was not used. If a compressed stream with a larger window 845ab9e68a2SToomas Soome size is given as input, inflate() will return with the error code 846ab9e68a2SToomas Soome Z_DATA_ERROR instead of trying to allocate a larger window. 847ab9e68a2SToomas Soome 848ab9e68a2SToomas Soome windowBits can also be zero to request that inflate use the window size in 849ab9e68a2SToomas Soome the zlib header of the compressed stream. 850ab9e68a2SToomas Soome 851ab9e68a2SToomas Soome windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 852ab9e68a2SToomas Soome determines the window size. inflate() will then process raw deflate data, 853ab9e68a2SToomas Soome not looking for a zlib or gzip header, not generating a check value, and not 854ab9e68a2SToomas Soome looking for any check values for comparison at the end of the stream. This 855ab9e68a2SToomas Soome is for use with other formats that use the deflate compressed data format 856ab9e68a2SToomas Soome such as zip. Those formats provide their own check values. If a custom 857ab9e68a2SToomas Soome format is developed using the raw deflate format for compressed data, it is 858ab9e68a2SToomas Soome recommended that a check value such as an Adler-32 or a CRC-32 be applied to 859ab9e68a2SToomas Soome the uncompressed data as is done in the zlib, gzip, and zip formats. For 860ab9e68a2SToomas Soome most applications, the zlib format should be used as is. Note that comments 861ab9e68a2SToomas Soome above on the use in deflateInit2() applies to the magnitude of windowBits. 862ab9e68a2SToomas Soome 863ab9e68a2SToomas Soome windowBits can also be greater than 15 for optional gzip decoding. Add 864ab9e68a2SToomas Soome 32 to windowBits to enable zlib and gzip decoding with automatic header 865ab9e68a2SToomas Soome detection, or add 16 to decode only the gzip format (the zlib format will 866ab9e68a2SToomas Soome return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a 867ab9e68a2SToomas Soome CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see 868*64c3d159SToomas Soome below), inflate() will *not* automatically decode concatenated gzip members. 869*64c3d159SToomas Soome inflate() will return Z_STREAM_END at the end of the gzip member. The state 870*64c3d159SToomas Soome would need to be reset to continue decoding a subsequent gzip member. This 871*64c3d159SToomas Soome *must* be done if there is more data after a gzip member, in order for the 872*64c3d159SToomas Soome decompression to be compliant with the gzip standard (RFC 1952). 873ab9e68a2SToomas Soome 874ab9e68a2SToomas Soome inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 875ab9e68a2SToomas Soome memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 876ab9e68a2SToomas Soome version assumed by the caller, or Z_STREAM_ERROR if the parameters are 877ab9e68a2SToomas Soome invalid, such as a null pointer to the structure. msg is set to null if 878ab9e68a2SToomas Soome there is no error message. inflateInit2 does not perform any decompression 879ab9e68a2SToomas Soome apart from possibly reading the zlib header if present: actual decompression 880ab9e68a2SToomas Soome will be done by inflate(). (So next_in and avail_in may be modified, but 881ab9e68a2SToomas Soome next_out and avail_out are unused and unchanged.) The current implementation 882ab9e68a2SToomas Soome of inflateInit2() does not process any header information -- that is 883ab9e68a2SToomas Soome deferred until inflate() is called. 884ab9e68a2SToomas Soome */ 885ab9e68a2SToomas Soome 886ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 887ab9e68a2SToomas Soome const Bytef *dictionary, 888ab9e68a2SToomas Soome uInt dictLength)); 889ab9e68a2SToomas Soome /* 890ab9e68a2SToomas Soome Initializes the decompression dictionary from the given uncompressed byte 891ab9e68a2SToomas Soome sequence. This function must be called immediately after a call of inflate, 892ab9e68a2SToomas Soome if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 893ab9e68a2SToomas Soome can be determined from the Adler-32 value returned by that call of inflate. 894ab9e68a2SToomas Soome The compressor and decompressor must use exactly the same dictionary (see 895ab9e68a2SToomas Soome deflateSetDictionary). For raw inflate, this function can be called at any 896ab9e68a2SToomas Soome time to set the dictionary. If the provided dictionary is smaller than the 897ab9e68a2SToomas Soome window and there is already data in the window, then the provided dictionary 898ab9e68a2SToomas Soome will amend what's there. The application must insure that the dictionary 899ab9e68a2SToomas Soome that was used for compression is provided. 900ab9e68a2SToomas Soome 901ab9e68a2SToomas Soome inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 902ab9e68a2SToomas Soome parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 903ab9e68a2SToomas Soome inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 904ab9e68a2SToomas Soome expected one (incorrect Adler-32 value). inflateSetDictionary does not 905ab9e68a2SToomas Soome perform any decompression: this will be done by subsequent calls of 906ab9e68a2SToomas Soome inflate(). 907ab9e68a2SToomas Soome */ 908ab9e68a2SToomas Soome 909ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, 910ab9e68a2SToomas Soome Bytef *dictionary, 911ab9e68a2SToomas Soome uInt *dictLength)); 912ab9e68a2SToomas Soome /* 913ab9e68a2SToomas Soome Returns the sliding dictionary being maintained by inflate. dictLength is 914ab9e68a2SToomas Soome set to the number of bytes in the dictionary, and that many bytes are copied 915ab9e68a2SToomas Soome to dictionary. dictionary must have enough space, where 32768 bytes is 916ab9e68a2SToomas Soome always enough. If inflateGetDictionary() is called with dictionary equal to 917ab9e68a2SToomas Soome Z_NULL, then only the dictionary length is returned, and nothing is copied. 918ab9e68a2SToomas Soome Similary, if dictLength is Z_NULL, then it is not set. 919ab9e68a2SToomas Soome 920ab9e68a2SToomas Soome inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the 921ab9e68a2SToomas Soome stream state is inconsistent. 922ab9e68a2SToomas Soome */ 923ab9e68a2SToomas Soome 924ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 925ab9e68a2SToomas Soome /* 926ab9e68a2SToomas Soome Skips invalid compressed data until a possible full flush point (see above 927ab9e68a2SToomas Soome for the description of deflate with Z_FULL_FLUSH) can be found, or until all 928ab9e68a2SToomas Soome available input is skipped. No output is provided. 929ab9e68a2SToomas Soome 930ab9e68a2SToomas Soome inflateSync searches for a 00 00 FF FF pattern in the compressed data. 931ab9e68a2SToomas Soome All full flush points have this pattern, but not all occurrences of this 932ab9e68a2SToomas Soome pattern are full flush points. 933ab9e68a2SToomas Soome 934ab9e68a2SToomas Soome inflateSync returns Z_OK if a possible full flush point has been found, 935ab9e68a2SToomas Soome Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point 936ab9e68a2SToomas Soome has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. 937ab9e68a2SToomas Soome In the success case, the application may save the current current value of 938ab9e68a2SToomas Soome total_in which indicates where valid compressed data was found. In the 939ab9e68a2SToomas Soome error case, the application may repeatedly call inflateSync, providing more 940ab9e68a2SToomas Soome input each time, until success or end of the input data. 941ab9e68a2SToomas Soome */ 942ab9e68a2SToomas Soome 943ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 944ab9e68a2SToomas Soome z_streamp source)); 945ab9e68a2SToomas Soome /* 946ab9e68a2SToomas Soome Sets the destination stream as a complete copy of the source stream. 947ab9e68a2SToomas Soome 948ab9e68a2SToomas Soome This function can be useful when randomly accessing a large stream. The 949ab9e68a2SToomas Soome first pass through the stream can periodically record the inflate state, 950ab9e68a2SToomas Soome allowing restarting inflate at those points when randomly accessing the 951ab9e68a2SToomas Soome stream. 952ab9e68a2SToomas Soome 953ab9e68a2SToomas Soome inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 954ab9e68a2SToomas Soome enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 955ab9e68a2SToomas Soome (such as zalloc being Z_NULL). msg is left unchanged in both source and 956ab9e68a2SToomas Soome destination. 957ab9e68a2SToomas Soome */ 958ab9e68a2SToomas Soome 959ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 960ab9e68a2SToomas Soome /* 961ab9e68a2SToomas Soome This function is equivalent to inflateEnd followed by inflateInit, 962ab9e68a2SToomas Soome but does not free and reallocate the internal decompression state. The 963ab9e68a2SToomas Soome stream will keep attributes that may have been set by inflateInit2. 964ab9e68a2SToomas Soome 965ab9e68a2SToomas Soome inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 966ab9e68a2SToomas Soome stream state was inconsistent (such as zalloc or state being Z_NULL). 967ab9e68a2SToomas Soome */ 968ab9e68a2SToomas Soome 969ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, 970ab9e68a2SToomas Soome int windowBits)); 971ab9e68a2SToomas Soome /* 972ab9e68a2SToomas Soome This function is the same as inflateReset, but it also permits changing 973ab9e68a2SToomas Soome the wrap and window size requests. The windowBits parameter is interpreted 974ab9e68a2SToomas Soome the same as it is for inflateInit2. If the window size is changed, then the 975ab9e68a2SToomas Soome memory allocated for the window is freed, and the window will be reallocated 976ab9e68a2SToomas Soome by inflate() if needed. 977ab9e68a2SToomas Soome 978ab9e68a2SToomas Soome inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 979ab9e68a2SToomas Soome stream state was inconsistent (such as zalloc or state being Z_NULL), or if 980ab9e68a2SToomas Soome the windowBits parameter is invalid. 981ab9e68a2SToomas Soome */ 982ab9e68a2SToomas Soome 983ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 984ab9e68a2SToomas Soome int bits, 985ab9e68a2SToomas Soome int value)); 986ab9e68a2SToomas Soome /* 987ab9e68a2SToomas Soome This function inserts bits in the inflate input stream. The intent is 988ab9e68a2SToomas Soome that this function is used to start inflating at a bit position in the 989ab9e68a2SToomas Soome middle of a byte. The provided bits will be used before any bytes are used 990ab9e68a2SToomas Soome from next_in. This function should only be used with raw inflate, and 991ab9e68a2SToomas Soome should be used before the first inflate() call after inflateInit2() or 992ab9e68a2SToomas Soome inflateReset(). bits must be less than or equal to 16, and that many of the 993ab9e68a2SToomas Soome least significant bits of value will be inserted in the input. 994ab9e68a2SToomas Soome 995ab9e68a2SToomas Soome If bits is negative, then the input stream bit buffer is emptied. Then 996ab9e68a2SToomas Soome inflatePrime() can be called again to put bits in the buffer. This is used 997ab9e68a2SToomas Soome to clear out bits leftover after feeding inflate a block description prior 998ab9e68a2SToomas Soome to feeding inflate codes. 999ab9e68a2SToomas Soome 1000ab9e68a2SToomas Soome inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 1001ab9e68a2SToomas Soome stream state was inconsistent. 1002ab9e68a2SToomas Soome */ 1003ab9e68a2SToomas Soome 1004ab9e68a2SToomas Soome ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); 1005ab9e68a2SToomas Soome /* 1006ab9e68a2SToomas Soome This function returns two values, one in the lower 16 bits of the return 1007ab9e68a2SToomas Soome value, and the other in the remaining upper bits, obtained by shifting the 1008ab9e68a2SToomas Soome return value down 16 bits. If the upper value is -1 and the lower value is 1009ab9e68a2SToomas Soome zero, then inflate() is currently decoding information outside of a block. 1010ab9e68a2SToomas Soome If the upper value is -1 and the lower value is non-zero, then inflate is in 1011ab9e68a2SToomas Soome the middle of a stored block, with the lower value equaling the number of 1012ab9e68a2SToomas Soome bytes from the input remaining to copy. If the upper value is not -1, then 1013ab9e68a2SToomas Soome it is the number of bits back from the current bit position in the input of 1014ab9e68a2SToomas Soome the code (literal or length/distance pair) currently being processed. In 1015ab9e68a2SToomas Soome that case the lower value is the number of bytes already emitted for that 1016ab9e68a2SToomas Soome code. 1017ab9e68a2SToomas Soome 1018ab9e68a2SToomas Soome A code is being processed if inflate is waiting for more input to complete 1019ab9e68a2SToomas Soome decoding of the code, or if it has completed decoding but is waiting for 1020ab9e68a2SToomas Soome more output space to write the literal or match data. 1021ab9e68a2SToomas Soome 1022ab9e68a2SToomas Soome inflateMark() is used to mark locations in the input data for random 1023ab9e68a2SToomas Soome access, which may be at bit positions, and to note those cases where the 1024ab9e68a2SToomas Soome output of a code may span boundaries of random access blocks. The current 1025ab9e68a2SToomas Soome location in the input stream can be determined from avail_in and data_type 1026ab9e68a2SToomas Soome as noted in the description for the Z_BLOCK flush parameter for inflate. 1027ab9e68a2SToomas Soome 1028ab9e68a2SToomas Soome inflateMark returns the value noted above, or -65536 if the provided 1029ab9e68a2SToomas Soome source stream state was inconsistent. 1030ab9e68a2SToomas Soome */ 1031ab9e68a2SToomas Soome 1032ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 1033ab9e68a2SToomas Soome gz_headerp head)); 1034ab9e68a2SToomas Soome /* 1035ab9e68a2SToomas Soome inflateGetHeader() requests that gzip header information be stored in the 1036ab9e68a2SToomas Soome provided gz_header structure. inflateGetHeader() may be called after 1037ab9e68a2SToomas Soome inflateInit2() or inflateReset(), and before the first call of inflate(). 1038ab9e68a2SToomas Soome As inflate() processes the gzip stream, head->done is zero until the header 1039ab9e68a2SToomas Soome is completed, at which time head->done is set to one. If a zlib stream is 1040ab9e68a2SToomas Soome being decoded, then head->done is set to -1 to indicate that there will be 1041ab9e68a2SToomas Soome no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be 1042ab9e68a2SToomas Soome used to force inflate() to return immediately after header processing is 1043ab9e68a2SToomas Soome complete and before any actual data is decompressed. 1044ab9e68a2SToomas Soome 1045ab9e68a2SToomas Soome The text, time, xflags, and os fields are filled in with the gzip header 1046ab9e68a2SToomas Soome contents. hcrc is set to true if there is a header CRC. (The header CRC 1047ab9e68a2SToomas Soome was valid if done is set to one.) If extra is not Z_NULL, then extra_max 1048ab9e68a2SToomas Soome contains the maximum number of bytes to write to extra. Once done is true, 1049ab9e68a2SToomas Soome extra_len contains the actual extra field length, and extra contains the 1050ab9e68a2SToomas Soome extra field, or that field truncated if extra_max is less than extra_len. 1051ab9e68a2SToomas Soome If name is not Z_NULL, then up to name_max characters are written there, 1052ab9e68a2SToomas Soome terminated with a zero unless the length is greater than name_max. If 1053ab9e68a2SToomas Soome comment is not Z_NULL, then up to comm_max characters are written there, 1054ab9e68a2SToomas Soome terminated with a zero unless the length is greater than comm_max. When any 1055ab9e68a2SToomas Soome of extra, name, or comment are not Z_NULL and the respective field is not 1056ab9e68a2SToomas Soome present in the header, then that field is set to Z_NULL to signal its 1057ab9e68a2SToomas Soome absence. This allows the use of deflateSetHeader() with the returned 1058ab9e68a2SToomas Soome structure to duplicate the header. However if those fields are set to 1059ab9e68a2SToomas Soome allocated memory, then the application will need to save those pointers 1060ab9e68a2SToomas Soome elsewhere so that they can be eventually freed. 1061ab9e68a2SToomas Soome 1062ab9e68a2SToomas Soome If inflateGetHeader is not used, then the header information is simply 1063ab9e68a2SToomas Soome discarded. The header is always checked for validity, including the header 1064ab9e68a2SToomas Soome CRC if present. inflateReset() will reset the process to discard the header 1065ab9e68a2SToomas Soome information. The application would need to call inflateGetHeader() again to 1066ab9e68a2SToomas Soome retrieve the header from the next gzip stream. 1067ab9e68a2SToomas Soome 1068ab9e68a2SToomas Soome inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 1069ab9e68a2SToomas Soome stream state was inconsistent. 1070ab9e68a2SToomas Soome */ 1071ab9e68a2SToomas Soome 1072ab9e68a2SToomas Soome /* 1073ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 1074ab9e68a2SToomas Soome unsigned char FAR *window)); 1075ab9e68a2SToomas Soome 1076ab9e68a2SToomas Soome Initialize the internal stream state for decompression using inflateBack() 1077ab9e68a2SToomas Soome calls. The fields zalloc, zfree and opaque in strm must be initialized 1078ab9e68a2SToomas Soome before the call. If zalloc and zfree are Z_NULL, then the default library- 1079ab9e68a2SToomas Soome derived memory allocation routines are used. windowBits is the base two 1080ab9e68a2SToomas Soome logarithm of the window size, in the range 8..15. window is a caller 1081ab9e68a2SToomas Soome supplied buffer of that size. Except for special applications where it is 1082ab9e68a2SToomas Soome assured that deflate was used with small window sizes, windowBits must be 15 1083ab9e68a2SToomas Soome and a 32K byte window must be supplied to be able to decompress general 1084ab9e68a2SToomas Soome deflate streams. 1085ab9e68a2SToomas Soome 1086ab9e68a2SToomas Soome See inflateBack() for the usage of these routines. 1087ab9e68a2SToomas Soome 1088ab9e68a2SToomas Soome inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 1089ab9e68a2SToomas Soome the parameters are invalid, Z_MEM_ERROR if the internal state could not be 1090ab9e68a2SToomas Soome allocated, or Z_VERSION_ERROR if the version of the library does not match 1091ab9e68a2SToomas Soome the version of the header file. 1092ab9e68a2SToomas Soome */ 1093ab9e68a2SToomas Soome 1094ab9e68a2SToomas Soome typedef unsigned (*in_func) OF((void FAR *, 1095ab9e68a2SToomas Soome z_const unsigned char FAR * FAR *)); 1096ab9e68a2SToomas Soome typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 1097ab9e68a2SToomas Soome 1098ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 1099ab9e68a2SToomas Soome in_func in, void FAR *in_desc, 1100ab9e68a2SToomas Soome out_func out, void FAR *out_desc)); 1101ab9e68a2SToomas Soome /* 1102ab9e68a2SToomas Soome inflateBack() does a raw inflate with a single call using a call-back 1103ab9e68a2SToomas Soome interface for input and output. This is potentially more efficient than 1104ab9e68a2SToomas Soome inflate() for file i/o applications, in that it avoids copying between the 1105ab9e68a2SToomas Soome output and the sliding window by simply making the window itself the output 1106ab9e68a2SToomas Soome buffer. inflate() can be faster on modern CPUs when used with large 1107ab9e68a2SToomas Soome buffers. inflateBack() trusts the application to not change the output 1108ab9e68a2SToomas Soome buffer passed by the output function, at least until inflateBack() returns. 1109ab9e68a2SToomas Soome 1110ab9e68a2SToomas Soome inflateBackInit() must be called first to allocate the internal state 1111ab9e68a2SToomas Soome and to initialize the state with the user-provided window buffer. 1112ab9e68a2SToomas Soome inflateBack() may then be used multiple times to inflate a complete, raw 1113ab9e68a2SToomas Soome deflate stream with each call. inflateBackEnd() is then called to free the 1114ab9e68a2SToomas Soome allocated state. 1115ab9e68a2SToomas Soome 1116ab9e68a2SToomas Soome A raw deflate stream is one with no zlib or gzip header or trailer. 1117ab9e68a2SToomas Soome This routine would normally be used in a utility that reads zip or gzip 1118ab9e68a2SToomas Soome files and writes out uncompressed files. The utility would decode the 1119ab9e68a2SToomas Soome header and process the trailer on its own, hence this routine expects only 1120ab9e68a2SToomas Soome the raw deflate stream to decompress. This is different from the default 1121ab9e68a2SToomas Soome behavior of inflate(), which expects a zlib header and trailer around the 1122ab9e68a2SToomas Soome deflate stream. 1123ab9e68a2SToomas Soome 1124ab9e68a2SToomas Soome inflateBack() uses two subroutines supplied by the caller that are then 1125ab9e68a2SToomas Soome called by inflateBack() for input and output. inflateBack() calls those 1126ab9e68a2SToomas Soome routines until it reads a complete deflate stream and writes out all of the 1127ab9e68a2SToomas Soome uncompressed data, or until it encounters an error. The function's 1128ab9e68a2SToomas Soome parameters and return types are defined above in the in_func and out_func 1129ab9e68a2SToomas Soome typedefs. inflateBack() will call in(in_desc, &buf) which should return the 1130ab9e68a2SToomas Soome number of bytes of provided input, and a pointer to that input in buf. If 1131ab9e68a2SToomas Soome there is no input available, in() must return zero -- buf is ignored in that 1132ab9e68a2SToomas Soome case -- and inflateBack() will return a buffer error. inflateBack() will 1133ab9e68a2SToomas Soome call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. 1134ab9e68a2SToomas Soome out() should return zero on success, or non-zero on failure. If out() 1135ab9e68a2SToomas Soome returns non-zero, inflateBack() will return with an error. Neither in() nor 1136ab9e68a2SToomas Soome out() are permitted to change the contents of the window provided to 1137ab9e68a2SToomas Soome inflateBackInit(), which is also the buffer that out() uses to write from. 1138ab9e68a2SToomas Soome The length written by out() will be at most the window size. Any non-zero 1139ab9e68a2SToomas Soome amount of input may be provided by in(). 1140ab9e68a2SToomas Soome 1141ab9e68a2SToomas Soome For convenience, inflateBack() can be provided input on the first call by 1142ab9e68a2SToomas Soome setting strm->next_in and strm->avail_in. If that input is exhausted, then 1143ab9e68a2SToomas Soome in() will be called. Therefore strm->next_in must be initialized before 1144ab9e68a2SToomas Soome calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 1145ab9e68a2SToomas Soome immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 1146ab9e68a2SToomas Soome must also be initialized, and then if strm->avail_in is not zero, input will 1147ab9e68a2SToomas Soome initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 1148ab9e68a2SToomas Soome 1149ab9e68a2SToomas Soome The in_desc and out_desc parameters of inflateBack() is passed as the 1150ab9e68a2SToomas Soome first parameter of in() and out() respectively when they are called. These 1151ab9e68a2SToomas Soome descriptors can be optionally used to pass any information that the caller- 1152ab9e68a2SToomas Soome supplied in() and out() functions need to do their job. 1153ab9e68a2SToomas Soome 1154ab9e68a2SToomas Soome On return, inflateBack() will set strm->next_in and strm->avail_in to 1155ab9e68a2SToomas Soome pass back any unused input that was provided by the last in() call. The 1156ab9e68a2SToomas Soome return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 1157ab9e68a2SToomas Soome if in() or out() returned an error, Z_DATA_ERROR if there was a format error 1158ab9e68a2SToomas Soome in the deflate stream (in which case strm->msg is set to indicate the nature 1159ab9e68a2SToomas Soome of the error), or Z_STREAM_ERROR if the stream was not properly initialized. 1160ab9e68a2SToomas Soome In the case of Z_BUF_ERROR, an input or output error can be distinguished 1161ab9e68a2SToomas Soome using strm->next_in which will be Z_NULL only if in() returned an error. If 1162ab9e68a2SToomas Soome strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning 1163ab9e68a2SToomas Soome non-zero. (in() will always be called before out(), so strm->next_in is 1164ab9e68a2SToomas Soome assured to be defined if out() returns non-zero.) Note that inflateBack() 1165ab9e68a2SToomas Soome cannot return Z_OK. 1166ab9e68a2SToomas Soome */ 1167ab9e68a2SToomas Soome 1168ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 1169ab9e68a2SToomas Soome /* 1170ab9e68a2SToomas Soome All memory allocated by inflateBackInit() is freed. 1171ab9e68a2SToomas Soome 1172ab9e68a2SToomas Soome inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 1173ab9e68a2SToomas Soome state was inconsistent. 1174ab9e68a2SToomas Soome */ 1175ab9e68a2SToomas Soome 1176ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 1177ab9e68a2SToomas Soome /* Return flags indicating compile-time options. 1178ab9e68a2SToomas Soome 1179ab9e68a2SToomas Soome Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 1180ab9e68a2SToomas Soome 1.0: size of uInt 1181ab9e68a2SToomas Soome 3.2: size of uLong 1182ab9e68a2SToomas Soome 5.4: size of voidpf (pointer) 1183ab9e68a2SToomas Soome 7.6: size of z_off_t 1184ab9e68a2SToomas Soome 1185ab9e68a2SToomas Soome Compiler, assembler, and debug options: 1186ab9e68a2SToomas Soome 8: ZLIB_DEBUG 1187ab9e68a2SToomas Soome 9: ASMV or ASMINF -- use ASM code 1188ab9e68a2SToomas Soome 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 1189ab9e68a2SToomas Soome 11: 0 (reserved) 1190ab9e68a2SToomas Soome 1191ab9e68a2SToomas Soome One-time table building (smaller code, but not thread-safe if true): 1192ab9e68a2SToomas Soome 12: BUILDFIXED -- build static block decoding tables when needed 1193ab9e68a2SToomas Soome 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 1194ab9e68a2SToomas Soome 14,15: 0 (reserved) 1195ab9e68a2SToomas Soome 1196ab9e68a2SToomas Soome Library content (indicates missing functionality): 1197ab9e68a2SToomas Soome 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 1198ab9e68a2SToomas Soome deflate code when not needed) 1199ab9e68a2SToomas Soome 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 1200ab9e68a2SToomas Soome and decode gzip streams (to avoid linking crc code) 1201ab9e68a2SToomas Soome 18-19: 0 (reserved) 1202ab9e68a2SToomas Soome 1203ab9e68a2SToomas Soome Operation variations (changes in library functionality): 1204ab9e68a2SToomas Soome 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 1205ab9e68a2SToomas Soome 21: FASTEST -- deflate algorithm with only one, lowest compression level 1206ab9e68a2SToomas Soome 22,23: 0 (reserved) 1207ab9e68a2SToomas Soome 1208ab9e68a2SToomas Soome The sprintf variant used by gzprintf (zero is best): 1209ab9e68a2SToomas Soome 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 1210ab9e68a2SToomas Soome 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 1211ab9e68a2SToomas Soome 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 1212ab9e68a2SToomas Soome 1213ab9e68a2SToomas Soome Remainder: 1214ab9e68a2SToomas Soome 27-31: 0 (reserved) 1215ab9e68a2SToomas Soome */ 1216ab9e68a2SToomas Soome 1217ab9e68a2SToomas Soome #ifndef Z_SOLO 1218ab9e68a2SToomas Soome 1219ab9e68a2SToomas Soome /* utility functions */ 1220ab9e68a2SToomas Soome 1221ab9e68a2SToomas Soome /* 1222ab9e68a2SToomas Soome The following utility functions are implemented on top of the basic 1223ab9e68a2SToomas Soome stream-oriented functions. To simplify the interface, some default options 1224ab9e68a2SToomas Soome are assumed (compression level and memory usage, standard memory allocation 1225ab9e68a2SToomas Soome functions). The source code of these utility functions can be modified if 1226ab9e68a2SToomas Soome you need special options. 1227ab9e68a2SToomas Soome */ 1228ab9e68a2SToomas Soome 1229ab9e68a2SToomas Soome ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 1230ab9e68a2SToomas Soome const Bytef *source, uLong sourceLen)); 1231ab9e68a2SToomas Soome /* 1232ab9e68a2SToomas Soome Compresses the source buffer into the destination buffer. sourceLen is 1233ab9e68a2SToomas Soome the byte length of the source buffer. Upon entry, destLen is the total size 1234ab9e68a2SToomas Soome of the destination buffer, which must be at least the value returned by 1235ab9e68a2SToomas Soome compressBound(sourceLen). Upon exit, destLen is the actual size of the 1236ab9e68a2SToomas Soome compressed data. compress() is equivalent to compress2() with a level 1237ab9e68a2SToomas Soome parameter of Z_DEFAULT_COMPRESSION. 1238ab9e68a2SToomas Soome 1239ab9e68a2SToomas Soome compress returns Z_OK if success, Z_MEM_ERROR if there was not 1240ab9e68a2SToomas Soome enough memory, Z_BUF_ERROR if there was not enough room in the output 1241ab9e68a2SToomas Soome buffer. 1242ab9e68a2SToomas Soome */ 1243ab9e68a2SToomas Soome 1244ab9e68a2SToomas Soome ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 1245ab9e68a2SToomas Soome const Bytef *source, uLong sourceLen, 1246ab9e68a2SToomas Soome int level)); 1247ab9e68a2SToomas Soome /* 1248ab9e68a2SToomas Soome Compresses the source buffer into the destination buffer. The level 1249ab9e68a2SToomas Soome parameter has the same meaning as in deflateInit. sourceLen is the byte 1250ab9e68a2SToomas Soome length of the source buffer. Upon entry, destLen is the total size of the 1251ab9e68a2SToomas Soome destination buffer, which must be at least the value returned by 1252ab9e68a2SToomas Soome compressBound(sourceLen). Upon exit, destLen is the actual size of the 1253ab9e68a2SToomas Soome compressed data. 1254ab9e68a2SToomas Soome 1255ab9e68a2SToomas Soome compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 1256ab9e68a2SToomas Soome memory, Z_BUF_ERROR if there was not enough room in the output buffer, 1257ab9e68a2SToomas Soome Z_STREAM_ERROR if the level parameter is invalid. 1258ab9e68a2SToomas Soome */ 1259ab9e68a2SToomas Soome 1260ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 1261ab9e68a2SToomas Soome /* 1262ab9e68a2SToomas Soome compressBound() returns an upper bound on the compressed size after 1263ab9e68a2SToomas Soome compress() or compress2() on sourceLen bytes. It would be used before a 1264ab9e68a2SToomas Soome compress() or compress2() call to allocate the destination buffer. 1265ab9e68a2SToomas Soome */ 1266ab9e68a2SToomas Soome 1267ab9e68a2SToomas Soome ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 1268ab9e68a2SToomas Soome const Bytef *source, uLong sourceLen)); 1269ab9e68a2SToomas Soome /* 1270ab9e68a2SToomas Soome Decompresses the source buffer into the destination buffer. sourceLen is 1271ab9e68a2SToomas Soome the byte length of the source buffer. Upon entry, destLen is the total size 1272ab9e68a2SToomas Soome of the destination buffer, which must be large enough to hold the entire 1273ab9e68a2SToomas Soome uncompressed data. (The size of the uncompressed data must have been saved 1274ab9e68a2SToomas Soome previously by the compressor and transmitted to the decompressor by some 1275ab9e68a2SToomas Soome mechanism outside the scope of this compression library.) Upon exit, destLen 1276ab9e68a2SToomas Soome is the actual size of the uncompressed data. 1277ab9e68a2SToomas Soome 1278ab9e68a2SToomas Soome uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1279ab9e68a2SToomas Soome enough memory, Z_BUF_ERROR if there was not enough room in the output 1280ab9e68a2SToomas Soome buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In 1281ab9e68a2SToomas Soome the case where there is not enough room, uncompress() will fill the output 1282ab9e68a2SToomas Soome buffer with the uncompressed data up to that point. 1283ab9e68a2SToomas Soome */ 1284ab9e68a2SToomas Soome 1285ab9e68a2SToomas Soome ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, 1286ab9e68a2SToomas Soome const Bytef *source, uLong *sourceLen)); 1287ab9e68a2SToomas Soome /* 1288ab9e68a2SToomas Soome Same as uncompress, except that sourceLen is a pointer, where the 1289ab9e68a2SToomas Soome length of the source is *sourceLen. On return, *sourceLen is the number of 1290ab9e68a2SToomas Soome source bytes consumed. 1291ab9e68a2SToomas Soome */ 1292ab9e68a2SToomas Soome 1293ab9e68a2SToomas Soome /* gzip file access functions */ 1294ab9e68a2SToomas Soome 1295ab9e68a2SToomas Soome /* 1296ab9e68a2SToomas Soome This library supports reading and writing files in gzip (.gz) format with 1297ab9e68a2SToomas Soome an interface similar to that of stdio, using the functions that start with 1298ab9e68a2SToomas Soome "gz". The gzip format is different from the zlib format. gzip is a gzip 1299ab9e68a2SToomas Soome wrapper, documented in RFC 1952, wrapped around a deflate stream. 1300ab9e68a2SToomas Soome */ 1301ab9e68a2SToomas Soome 1302ab9e68a2SToomas Soome typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ 1303ab9e68a2SToomas Soome 1304ab9e68a2SToomas Soome /* 1305ab9e68a2SToomas Soome ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 1306ab9e68a2SToomas Soome 1307*64c3d159SToomas Soome Open the gzip (.gz) file at path for reading and decompressing, or 1308*64c3d159SToomas Soome compressing and writing. The mode parameter is as in fopen ("rb" or "wb") 1309*64c3d159SToomas Soome but can also include a compression level ("wb9") or a strategy: 'f' for 1310*64c3d159SToomas Soome filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h", 1311*64c3d159SToomas Soome 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression 1312*64c3d159SToomas Soome as in "wb9F". (See the description of deflateInit2 for more information 1313*64c3d159SToomas Soome about the strategy parameter.) 'T' will request transparent writing or 1314*64c3d159SToomas Soome appending with no compression and not using the gzip format. 1315ab9e68a2SToomas Soome 1316ab9e68a2SToomas Soome "a" can be used instead of "w" to request that the gzip stream that will 1317ab9e68a2SToomas Soome be written be appended to the file. "+" will result in an error, since 1318ab9e68a2SToomas Soome reading and writing to the same gzip file is not supported. The addition of 1319ab9e68a2SToomas Soome "x" when writing will create the file exclusively, which fails if the file 1320ab9e68a2SToomas Soome already exists. On systems that support it, the addition of "e" when 1321ab9e68a2SToomas Soome reading or writing will set the flag to close the file on an execve() call. 1322ab9e68a2SToomas Soome 1323ab9e68a2SToomas Soome These functions, as well as gzip, will read and decode a sequence of gzip 1324ab9e68a2SToomas Soome streams in a file. The append function of gzopen() can be used to create 1325ab9e68a2SToomas Soome such a file. (Also see gzflush() for another way to do this.) When 1326ab9e68a2SToomas Soome appending, gzopen does not test whether the file begins with a gzip stream, 1327ab9e68a2SToomas Soome nor does it look for the end of the gzip streams to begin appending. gzopen 1328ab9e68a2SToomas Soome will simply append a gzip stream to the existing file. 1329ab9e68a2SToomas Soome 1330ab9e68a2SToomas Soome gzopen can be used to read a file which is not in gzip format; in this 1331ab9e68a2SToomas Soome case gzread will directly read from the file without decompression. When 1332ab9e68a2SToomas Soome reading, this will be detected automatically by looking for the magic two- 1333ab9e68a2SToomas Soome byte gzip header. 1334ab9e68a2SToomas Soome 1335ab9e68a2SToomas Soome gzopen returns NULL if the file could not be opened, if there was 1336ab9e68a2SToomas Soome insufficient memory to allocate the gzFile state, or if an invalid mode was 1337ab9e68a2SToomas Soome specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). 1338ab9e68a2SToomas Soome errno can be checked to determine if the reason gzopen failed was that the 1339ab9e68a2SToomas Soome file could not be opened. 1340ab9e68a2SToomas Soome */ 1341ab9e68a2SToomas Soome 1342ab9e68a2SToomas Soome ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 1343ab9e68a2SToomas Soome /* 1344*64c3d159SToomas Soome Associate a gzFile with the file descriptor fd. File descriptors are 1345*64c3d159SToomas Soome obtained from calls like open, dup, creat, pipe or fileno (if the file has 1346*64c3d159SToomas Soome been previously opened with fopen). The mode parameter is as in gzopen. 1347ab9e68a2SToomas Soome 1348ab9e68a2SToomas Soome The next call of gzclose on the returned gzFile will also close the file 1349ab9e68a2SToomas Soome descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor 1350ab9e68a2SToomas Soome fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, 1351ab9e68a2SToomas Soome mode);. The duplicated descriptor should be saved to avoid a leak, since 1352ab9e68a2SToomas Soome gzdopen does not close fd if it fails. If you are using fileno() to get the 1353ab9e68a2SToomas Soome file descriptor from a FILE *, then you will have to use dup() to avoid 1354ab9e68a2SToomas Soome double-close()ing the file descriptor. Both gzclose() and fclose() will 1355ab9e68a2SToomas Soome close the associated file descriptor, so they need to have different file 1356ab9e68a2SToomas Soome descriptors. 1357ab9e68a2SToomas Soome 1358ab9e68a2SToomas Soome gzdopen returns NULL if there was insufficient memory to allocate the 1359ab9e68a2SToomas Soome gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not 1360ab9e68a2SToomas Soome provided, or '+' was provided), or if fd is -1. The file descriptor is not 1361ab9e68a2SToomas Soome used until the next gz* read, write, seek, or close operation, so gzdopen 1362ab9e68a2SToomas Soome will not detect if fd is invalid (unless fd is -1). 1363ab9e68a2SToomas Soome */ 1364ab9e68a2SToomas Soome 1365ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); 1366ab9e68a2SToomas Soome /* 1367*64c3d159SToomas Soome Set the internal buffer size used by this library's functions for file to 1368*64c3d159SToomas Soome size. The default buffer size is 8192 bytes. This function must be called 1369*64c3d159SToomas Soome after gzopen() or gzdopen(), and before any other calls that read or write 1370*64c3d159SToomas Soome the file. The buffer memory allocation is always deferred to the first read 1371*64c3d159SToomas Soome or write. Three times that size in buffer space is allocated. A larger 1372*64c3d159SToomas Soome buffer size of, for example, 64K or 128K bytes will noticeably increase the 1373*64c3d159SToomas Soome speed of decompression (reading). 1374ab9e68a2SToomas Soome 1375ab9e68a2SToomas Soome The new buffer size also affects the maximum length for gzprintf(). 1376ab9e68a2SToomas Soome 1377ab9e68a2SToomas Soome gzbuffer() returns 0 on success, or -1 on failure, such as being called 1378ab9e68a2SToomas Soome too late. 1379ab9e68a2SToomas Soome */ 1380ab9e68a2SToomas Soome 1381ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 1382ab9e68a2SToomas Soome /* 1383*64c3d159SToomas Soome Dynamically update the compression level and strategy for file. See the 1384*64c3d159SToomas Soome description of deflateInit2 for the meaning of these parameters. Previously 1385*64c3d159SToomas Soome provided data is flushed before applying the parameter changes. 1386ab9e68a2SToomas Soome 1387ab9e68a2SToomas Soome gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not 1388ab9e68a2SToomas Soome opened for writing, Z_ERRNO if there is an error writing the flushed data, 1389ab9e68a2SToomas Soome or Z_MEM_ERROR if there is a memory allocation error. 1390ab9e68a2SToomas Soome */ 1391ab9e68a2SToomas Soome 1392ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 1393ab9e68a2SToomas Soome /* 1394*64c3d159SToomas Soome Read and decompress up to len uncompressed bytes from file into buf. If 1395ab9e68a2SToomas Soome the input file is not in gzip format, gzread copies the given number of 1396ab9e68a2SToomas Soome bytes into the buffer directly from the file. 1397ab9e68a2SToomas Soome 1398ab9e68a2SToomas Soome After reaching the end of a gzip stream in the input, gzread will continue 1399ab9e68a2SToomas Soome to read, looking for another gzip stream. Any number of gzip streams may be 1400ab9e68a2SToomas Soome concatenated in the input file, and will all be decompressed by gzread(). 1401ab9e68a2SToomas Soome If something other than a gzip stream is encountered after a gzip stream, 1402ab9e68a2SToomas Soome that remaining trailing garbage is ignored (and no error is returned). 1403ab9e68a2SToomas Soome 1404ab9e68a2SToomas Soome gzread can be used to read a gzip file that is being concurrently written. 1405ab9e68a2SToomas Soome Upon reaching the end of the input, gzread will return with the available 1406ab9e68a2SToomas Soome data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then 1407ab9e68a2SToomas Soome gzclearerr can be used to clear the end of file indicator in order to permit 1408ab9e68a2SToomas Soome gzread to be tried again. Z_OK indicates that a gzip stream was completed 1409ab9e68a2SToomas Soome on the last gzread. Z_BUF_ERROR indicates that the input file ended in the 1410ab9e68a2SToomas Soome middle of a gzip stream. Note that gzread does not return -1 in the event 1411ab9e68a2SToomas Soome of an incomplete gzip stream. This error is deferred until gzclose(), which 1412ab9e68a2SToomas Soome will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip 1413ab9e68a2SToomas Soome stream. Alternatively, gzerror can be used before gzclose to detect this 1414ab9e68a2SToomas Soome case. 1415ab9e68a2SToomas Soome 1416ab9e68a2SToomas Soome gzread returns the number of uncompressed bytes actually read, less than 1417ab9e68a2SToomas Soome len for end of file, or -1 for error. If len is too large to fit in an int, 1418ab9e68a2SToomas Soome then nothing is read, -1 is returned, and the error state is set to 1419ab9e68a2SToomas Soome Z_STREAM_ERROR. 1420ab9e68a2SToomas Soome */ 1421ab9e68a2SToomas Soome 1422ab9e68a2SToomas Soome ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, 1423ab9e68a2SToomas Soome gzFile file)); 1424ab9e68a2SToomas Soome /* 1425*64c3d159SToomas Soome Read and decompress up to nitems items of size size from file into buf, 1426*64c3d159SToomas Soome otherwise operating as gzread() does. This duplicates the interface of 1427*64c3d159SToomas Soome stdio's fread(), with size_t request and return types. If the library 1428*64c3d159SToomas Soome defines size_t, then z_size_t is identical to size_t. If not, then z_size_t 1429*64c3d159SToomas Soome is an unsigned integer type that can contain a pointer. 1430ab9e68a2SToomas Soome 1431ab9e68a2SToomas Soome gzfread() returns the number of full items read of size size, or zero if 1432ab9e68a2SToomas Soome the end of the file was reached and a full item could not be read, or if 1433ab9e68a2SToomas Soome there was an error. gzerror() must be consulted if zero is returned in 1434ab9e68a2SToomas Soome order to determine if there was an error. If the multiplication of size and 1435ab9e68a2SToomas Soome nitems overflows, i.e. the product does not fit in a z_size_t, then nothing 1436ab9e68a2SToomas Soome is read, zero is returned, and the error state is set to Z_STREAM_ERROR. 1437ab9e68a2SToomas Soome 1438ab9e68a2SToomas Soome In the event that the end of file is reached and only a partial item is 1439ab9e68a2SToomas Soome available at the end, i.e. the remaining uncompressed data length is not a 1440ab9e68a2SToomas Soome multiple of size, then the final partial item is nevetheless read into buf 1441ab9e68a2SToomas Soome and the end-of-file flag is set. The length of the partial item read is not 1442ab9e68a2SToomas Soome provided, but could be inferred from the result of gztell(). This behavior 1443ab9e68a2SToomas Soome is the same as the behavior of fread() implementations in common libraries, 1444ab9e68a2SToomas Soome but it prevents the direct use of gzfread() to read a concurrently written 1445ab9e68a2SToomas Soome file, reseting and retrying on end-of-file, when size is not 1. 1446ab9e68a2SToomas Soome */ 1447ab9e68a2SToomas Soome 1448*64c3d159SToomas Soome ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); 1449ab9e68a2SToomas Soome /* 1450*64c3d159SToomas Soome Compress and write the len uncompressed bytes at buf to file. gzwrite 1451*64c3d159SToomas Soome returns the number of uncompressed bytes written or 0 in case of error. 1452ab9e68a2SToomas Soome */ 1453ab9e68a2SToomas Soome 1454ab9e68a2SToomas Soome ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, 1455ab9e68a2SToomas Soome z_size_t nitems, gzFile file)); 1456ab9e68a2SToomas Soome /* 1457*64c3d159SToomas Soome Compress and write nitems items of size size from buf to file, duplicating 1458ab9e68a2SToomas Soome the interface of stdio's fwrite(), with size_t request and return types. If 1459ab9e68a2SToomas Soome the library defines size_t, then z_size_t is identical to size_t. If not, 1460ab9e68a2SToomas Soome then z_size_t is an unsigned integer type that can contain a pointer. 1461ab9e68a2SToomas Soome 1462ab9e68a2SToomas Soome gzfwrite() returns the number of full items written of size size, or zero 1463ab9e68a2SToomas Soome if there was an error. If the multiplication of size and nitems overflows, 1464ab9e68a2SToomas Soome i.e. the product does not fit in a z_size_t, then nothing is written, zero 1465ab9e68a2SToomas Soome is returned, and the error state is set to Z_STREAM_ERROR. 1466ab9e68a2SToomas Soome */ 1467ab9e68a2SToomas Soome 1468ab9e68a2SToomas Soome ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); 1469ab9e68a2SToomas Soome /* 1470*64c3d159SToomas Soome Convert, format, compress, and write the arguments (...) to file under 1471*64c3d159SToomas Soome control of the string format, as in fprintf. gzprintf returns the number of 1472ab9e68a2SToomas Soome uncompressed bytes actually written, or a negative zlib error code in case 1473ab9e68a2SToomas Soome of error. The number of uncompressed bytes written is limited to 8191, or 1474ab9e68a2SToomas Soome one less than the buffer size given to gzbuffer(). The caller should assure 1475ab9e68a2SToomas Soome that this limit is not exceeded. If it is exceeded, then gzprintf() will 1476ab9e68a2SToomas Soome return an error (0) with nothing written. In this case, there may also be a 1477ab9e68a2SToomas Soome buffer overflow with unpredictable consequences, which is possible only if 1478*64c3d159SToomas Soome zlib was compiled with the insecure functions sprintf() or vsprintf(), 1479ab9e68a2SToomas Soome because the secure snprintf() or vsnprintf() functions were not available. 1480ab9e68a2SToomas Soome This can be determined using zlibCompileFlags(). 1481ab9e68a2SToomas Soome */ 1482ab9e68a2SToomas Soome 1483ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 1484ab9e68a2SToomas Soome /* 1485*64c3d159SToomas Soome Compress and write the given null-terminated string s to file, excluding 1486ab9e68a2SToomas Soome the terminating null character. 1487ab9e68a2SToomas Soome 1488ab9e68a2SToomas Soome gzputs returns the number of characters written, or -1 in case of error. 1489ab9e68a2SToomas Soome */ 1490ab9e68a2SToomas Soome 1491ab9e68a2SToomas Soome ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 1492ab9e68a2SToomas Soome /* 1493*64c3d159SToomas Soome Read and decompress bytes from file into buf, until len-1 characters are 1494*64c3d159SToomas Soome read, or until a newline character is read and transferred to buf, or an 1495*64c3d159SToomas Soome end-of-file condition is encountered. If any characters are read or if len 1496*64c3d159SToomas Soome is one, the string is terminated with a null character. If no characters 1497*64c3d159SToomas Soome are read due to an end-of-file or len is less than one, then the buffer is 1498*64c3d159SToomas Soome left untouched. 1499ab9e68a2SToomas Soome 1500ab9e68a2SToomas Soome gzgets returns buf which is a null-terminated string, or it returns NULL 1501ab9e68a2SToomas Soome for end-of-file or in case of error. If there was an error, the contents at 1502ab9e68a2SToomas Soome buf are indeterminate. 1503ab9e68a2SToomas Soome */ 1504ab9e68a2SToomas Soome 1505ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 1506ab9e68a2SToomas Soome /* 1507*64c3d159SToomas Soome Compress and write c, converted to an unsigned char, into file. gzputc 1508ab9e68a2SToomas Soome returns the value that was written, or -1 in case of error. 1509ab9e68a2SToomas Soome */ 1510ab9e68a2SToomas Soome 1511ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 1512ab9e68a2SToomas Soome /* 1513*64c3d159SToomas Soome Read and decompress one byte from file. gzgetc returns this byte or -1 1514ab9e68a2SToomas Soome in case of end of file or error. This is implemented as a macro for speed. 1515ab9e68a2SToomas Soome As such, it does not do all of the checking the other functions do. I.e. 1516ab9e68a2SToomas Soome it does not check to see if file is NULL, nor whether the structure file 1517ab9e68a2SToomas Soome points to has been clobbered or not. 1518ab9e68a2SToomas Soome */ 1519ab9e68a2SToomas Soome 1520ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 1521ab9e68a2SToomas Soome /* 1522*64c3d159SToomas Soome Push c back onto the stream for file to be read as the first character on 1523*64c3d159SToomas Soome the next read. At least one character of push-back is always allowed. 1524ab9e68a2SToomas Soome gzungetc() returns the character pushed, or -1 on failure. gzungetc() will 1525ab9e68a2SToomas Soome fail if c is -1, and may fail if a character has been pushed but not read 1526ab9e68a2SToomas Soome yet. If gzungetc is used immediately after gzopen or gzdopen, at least the 1527ab9e68a2SToomas Soome output buffer size of pushed characters is allowed. (See gzbuffer above.) 1528ab9e68a2SToomas Soome The pushed character will be discarded if the stream is repositioned with 1529ab9e68a2SToomas Soome gzseek() or gzrewind(). 1530ab9e68a2SToomas Soome */ 1531ab9e68a2SToomas Soome 1532ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 1533ab9e68a2SToomas Soome /* 1534*64c3d159SToomas Soome Flush all pending output to file. The parameter flush is as in the 1535*64c3d159SToomas Soome deflate() function. The return value is the zlib error number (see function 1536*64c3d159SToomas Soome gzerror below). gzflush is only permitted when writing. 1537ab9e68a2SToomas Soome 1538ab9e68a2SToomas Soome If the flush parameter is Z_FINISH, the remaining data is written and the 1539ab9e68a2SToomas Soome gzip stream is completed in the output. If gzwrite() is called again, a new 1540ab9e68a2SToomas Soome gzip stream will be started in the output. gzread() is able to read such 1541ab9e68a2SToomas Soome concatenated gzip streams. 1542ab9e68a2SToomas Soome 1543ab9e68a2SToomas Soome gzflush should be called only when strictly necessary because it will 1544ab9e68a2SToomas Soome degrade compression if called too often. 1545ab9e68a2SToomas Soome */ 1546ab9e68a2SToomas Soome 1547ab9e68a2SToomas Soome /* 1548ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 1549ab9e68a2SToomas Soome z_off_t offset, int whence)); 1550ab9e68a2SToomas Soome 1551*64c3d159SToomas Soome Set the starting position to offset relative to whence for the next gzread 1552*64c3d159SToomas Soome or gzwrite on file. The offset represents a number of bytes in the 1553ab9e68a2SToomas Soome uncompressed data stream. The whence parameter is defined as in lseek(2); 1554ab9e68a2SToomas Soome the value SEEK_END is not supported. 1555ab9e68a2SToomas Soome 1556ab9e68a2SToomas Soome If the file is opened for reading, this function is emulated but can be 1557ab9e68a2SToomas Soome extremely slow. If the file is opened for writing, only forward seeks are 1558ab9e68a2SToomas Soome supported; gzseek then compresses a sequence of zeroes up to the new 1559ab9e68a2SToomas Soome starting position. 1560ab9e68a2SToomas Soome 1561ab9e68a2SToomas Soome gzseek returns the resulting offset location as measured in bytes from 1562ab9e68a2SToomas Soome the beginning of the uncompressed stream, or -1 in case of error, in 1563ab9e68a2SToomas Soome particular if the file is opened for writing and the new starting position 1564ab9e68a2SToomas Soome would be before the current position. 1565ab9e68a2SToomas Soome */ 1566ab9e68a2SToomas Soome 1567ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 1568ab9e68a2SToomas Soome /* 1569*64c3d159SToomas Soome Rewind file. This function is supported only for reading. 1570ab9e68a2SToomas Soome 1571*64c3d159SToomas Soome gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET). 1572ab9e68a2SToomas Soome */ 1573ab9e68a2SToomas Soome 1574ab9e68a2SToomas Soome /* 1575ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 1576ab9e68a2SToomas Soome 1577*64c3d159SToomas Soome Return the starting position for the next gzread or gzwrite on file. 1578*64c3d159SToomas Soome This position represents a number of bytes in the uncompressed data stream, 1579*64c3d159SToomas Soome and is zero when starting, even if appending or reading a gzip stream from 1580*64c3d159SToomas Soome the middle of a file using gzdopen(). 1581ab9e68a2SToomas Soome 1582ab9e68a2SToomas Soome gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 1583ab9e68a2SToomas Soome */ 1584ab9e68a2SToomas Soome 1585ab9e68a2SToomas Soome /* 1586ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); 1587ab9e68a2SToomas Soome 1588*64c3d159SToomas Soome Return the current compressed (actual) read or write offset of file. This 1589*64c3d159SToomas Soome offset includes the count of bytes that precede the gzip stream, for example 1590*64c3d159SToomas Soome when appending or when using gzdopen() for reading. When reading, the 1591*64c3d159SToomas Soome offset does not include as yet unused buffered input. This information can 1592*64c3d159SToomas Soome be used for a progress indicator. On error, gzoffset() returns -1. 1593ab9e68a2SToomas Soome */ 1594ab9e68a2SToomas Soome 1595ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 1596ab9e68a2SToomas Soome /* 1597*64c3d159SToomas Soome Return true (1) if the end-of-file indicator for file has been set while 1598*64c3d159SToomas Soome reading, false (0) otherwise. Note that the end-of-file indicator is set 1599*64c3d159SToomas Soome only if the read tried to go past the end of the input, but came up short. 1600*64c3d159SToomas Soome Therefore, just like feof(), gzeof() may return false even if there is no 1601*64c3d159SToomas Soome more data to read, in the event that the last read request was for the exact 1602*64c3d159SToomas Soome number of bytes remaining in the input file. This will happen if the input 1603*64c3d159SToomas Soome file size is an exact multiple of the buffer size. 1604ab9e68a2SToomas Soome 1605ab9e68a2SToomas Soome If gzeof() returns true, then the read functions will return no more data, 1606ab9e68a2SToomas Soome unless the end-of-file indicator is reset by gzclearerr() and the input file 1607ab9e68a2SToomas Soome has grown since the previous end of file was detected. 1608ab9e68a2SToomas Soome */ 1609ab9e68a2SToomas Soome 1610ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 1611ab9e68a2SToomas Soome /* 1612*64c3d159SToomas Soome Return true (1) if file is being copied directly while reading, or false 1613ab9e68a2SToomas Soome (0) if file is a gzip stream being decompressed. 1614ab9e68a2SToomas Soome 1615ab9e68a2SToomas Soome If the input file is empty, gzdirect() will return true, since the input 1616ab9e68a2SToomas Soome does not contain a gzip stream. 1617ab9e68a2SToomas Soome 1618ab9e68a2SToomas Soome If gzdirect() is used immediately after gzopen() or gzdopen() it will 1619ab9e68a2SToomas Soome cause buffers to be allocated to allow reading the file to determine if it 1620ab9e68a2SToomas Soome is a gzip file. Therefore if gzbuffer() is used, it should be called before 1621ab9e68a2SToomas Soome gzdirect(). 1622ab9e68a2SToomas Soome 1623ab9e68a2SToomas Soome When writing, gzdirect() returns true (1) if transparent writing was 1624ab9e68a2SToomas Soome requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: 1625ab9e68a2SToomas Soome gzdirect() is not needed when writing. Transparent writing must be 1626ab9e68a2SToomas Soome explicitly requested, so the application already knows the answer. When 1627ab9e68a2SToomas Soome linking statically, using gzdirect() will include all of the zlib code for 1628ab9e68a2SToomas Soome gzip file reading and decompression, which may not be desired.) 1629ab9e68a2SToomas Soome */ 1630ab9e68a2SToomas Soome 1631ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 1632ab9e68a2SToomas Soome /* 1633*64c3d159SToomas Soome Flush all pending output for file, if necessary, close file and 1634*64c3d159SToomas Soome deallocate the (de)compression state. Note that once file is closed, you 1635ab9e68a2SToomas Soome cannot call gzerror with file, since its structures have been deallocated. 1636ab9e68a2SToomas Soome gzclose must not be called more than once on the same file, just as free 1637ab9e68a2SToomas Soome must not be called more than once on the same allocation. 1638ab9e68a2SToomas Soome 1639ab9e68a2SToomas Soome gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a 1640ab9e68a2SToomas Soome file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the 1641ab9e68a2SToomas Soome last read ended in the middle of a gzip stream, or Z_OK on success. 1642ab9e68a2SToomas Soome */ 1643ab9e68a2SToomas Soome 1644ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); 1645ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); 1646ab9e68a2SToomas Soome /* 1647ab9e68a2SToomas Soome Same as gzclose(), but gzclose_r() is only for use when reading, and 1648ab9e68a2SToomas Soome gzclose_w() is only for use when writing or appending. The advantage to 1649ab9e68a2SToomas Soome using these instead of gzclose() is that they avoid linking in zlib 1650ab9e68a2SToomas Soome compression or decompression code that is not used when only reading or only 1651ab9e68a2SToomas Soome writing respectively. If gzclose() is used, then both compression and 1652ab9e68a2SToomas Soome decompression code will be included the application when linking to a static 1653ab9e68a2SToomas Soome zlib library. 1654ab9e68a2SToomas Soome */ 1655ab9e68a2SToomas Soome 1656ab9e68a2SToomas Soome ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 1657ab9e68a2SToomas Soome /* 1658*64c3d159SToomas Soome Return the error message for the last error which occurred on file. 1659*64c3d159SToomas Soome errnum is set to zlib error number. If an error occurred in the file system 1660*64c3d159SToomas Soome and not in the compression library, errnum is set to Z_ERRNO and the 1661*64c3d159SToomas Soome application may consult errno to get the exact error code. 1662ab9e68a2SToomas Soome 1663ab9e68a2SToomas Soome The application must not modify the returned string. Future calls to 1664ab9e68a2SToomas Soome this function may invalidate the previously returned string. If file is 1665ab9e68a2SToomas Soome closed, then the string previously returned by gzerror will no longer be 1666ab9e68a2SToomas Soome available. 1667ab9e68a2SToomas Soome 1668ab9e68a2SToomas Soome gzerror() should be used to distinguish errors from end-of-file for those 1669ab9e68a2SToomas Soome functions above that do not distinguish those cases in their return values. 1670ab9e68a2SToomas Soome */ 1671ab9e68a2SToomas Soome 1672ab9e68a2SToomas Soome ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 1673ab9e68a2SToomas Soome /* 1674*64c3d159SToomas Soome Clear the error and end-of-file flags for file. This is analogous to the 1675ab9e68a2SToomas Soome clearerr() function in stdio. This is useful for continuing to read a gzip 1676ab9e68a2SToomas Soome file that is being written concurrently. 1677ab9e68a2SToomas Soome */ 1678ab9e68a2SToomas Soome 1679ab9e68a2SToomas Soome #endif /* !Z_SOLO */ 1680ab9e68a2SToomas Soome 1681ab9e68a2SToomas Soome /* checksum functions */ 1682ab9e68a2SToomas Soome 1683ab9e68a2SToomas Soome /* 1684ab9e68a2SToomas Soome These functions are not related to compression but are exported 1685ab9e68a2SToomas Soome anyway because they might be useful in applications using the compression 1686ab9e68a2SToomas Soome library. 1687ab9e68a2SToomas Soome */ 1688ab9e68a2SToomas Soome 1689ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 1690ab9e68a2SToomas Soome /* 1691ab9e68a2SToomas Soome Update a running Adler-32 checksum with the bytes buf[0..len-1] and 1692*64c3d159SToomas Soome return the updated checksum. An Adler-32 value is in the range of a 32-bit 1693*64c3d159SToomas Soome unsigned integer. If buf is Z_NULL, this function returns the required 1694*64c3d159SToomas Soome initial value for the checksum. 1695ab9e68a2SToomas Soome 1696ab9e68a2SToomas Soome An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed 1697ab9e68a2SToomas Soome much faster. 1698ab9e68a2SToomas Soome 1699ab9e68a2SToomas Soome Usage example: 1700ab9e68a2SToomas Soome 1701ab9e68a2SToomas Soome uLong adler = adler32(0L, Z_NULL, 0); 1702ab9e68a2SToomas Soome 1703ab9e68a2SToomas Soome while (read_buffer(buffer, length) != EOF) { 1704ab9e68a2SToomas Soome adler = adler32(adler, buffer, length); 1705ab9e68a2SToomas Soome } 1706ab9e68a2SToomas Soome if (adler != original_adler) error(); 1707ab9e68a2SToomas Soome */ 1708ab9e68a2SToomas Soome 1709ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, 1710ab9e68a2SToomas Soome z_size_t len)); 1711ab9e68a2SToomas Soome /* 1712ab9e68a2SToomas Soome Same as adler32(), but with a size_t length. 1713ab9e68a2SToomas Soome */ 1714ab9e68a2SToomas Soome 1715ab9e68a2SToomas Soome /* 1716ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 1717ab9e68a2SToomas Soome z_off_t len2)); 1718ab9e68a2SToomas Soome 1719ab9e68a2SToomas Soome Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 1720ab9e68a2SToomas Soome and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 1721ab9e68a2SToomas Soome each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 1722ab9e68a2SToomas Soome seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note 1723ab9e68a2SToomas Soome that the z_off_t type (like off_t) is a signed integer. If len2 is 1724ab9e68a2SToomas Soome negative, the result has no meaning or utility. 1725ab9e68a2SToomas Soome */ 1726ab9e68a2SToomas Soome 1727ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 1728ab9e68a2SToomas Soome /* 1729ab9e68a2SToomas Soome Update a running CRC-32 with the bytes buf[0..len-1] and return the 1730*64c3d159SToomas Soome updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. 1731*64c3d159SToomas Soome If buf is Z_NULL, this function returns the required initial value for the 1732*64c3d159SToomas Soome crc. Pre- and post-conditioning (one's complement) is performed within this 1733*64c3d159SToomas Soome function so it shouldn't be done by the application. 1734ab9e68a2SToomas Soome 1735ab9e68a2SToomas Soome Usage example: 1736ab9e68a2SToomas Soome 1737ab9e68a2SToomas Soome uLong crc = crc32(0L, Z_NULL, 0); 1738ab9e68a2SToomas Soome 1739ab9e68a2SToomas Soome while (read_buffer(buffer, length) != EOF) { 1740ab9e68a2SToomas Soome crc = crc32(crc, buffer, length); 1741ab9e68a2SToomas Soome } 1742ab9e68a2SToomas Soome if (crc != original_crc) error(); 1743ab9e68a2SToomas Soome */ 1744ab9e68a2SToomas Soome 1745*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, 1746ab9e68a2SToomas Soome z_size_t len)); 1747ab9e68a2SToomas Soome /* 1748ab9e68a2SToomas Soome Same as crc32(), but with a size_t length. 1749ab9e68a2SToomas Soome */ 1750ab9e68a2SToomas Soome 1751ab9e68a2SToomas Soome /* 1752ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 1753ab9e68a2SToomas Soome 1754ab9e68a2SToomas Soome Combine two CRC-32 check values into one. For two sequences of bytes, 1755ab9e68a2SToomas Soome seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 1756ab9e68a2SToomas Soome calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 1757ab9e68a2SToomas Soome check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 1758ab9e68a2SToomas Soome len2. 1759ab9e68a2SToomas Soome */ 1760ab9e68a2SToomas Soome 1761*64c3d159SToomas Soome /* 1762*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); 1763*64c3d159SToomas Soome 1764*64c3d159SToomas Soome Return the operator corresponding to length len2, to be used with 1765*64c3d159SToomas Soome crc32_combine_op(). 1766*64c3d159SToomas Soome */ 1767*64c3d159SToomas Soome 1768*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); 1769*64c3d159SToomas Soome /* 1770*64c3d159SToomas Soome Give the same result as crc32_combine(), using op in place of len2. op is 1771*64c3d159SToomas Soome is generated from len2 by crc32_combine_gen(). This will be faster than 1772*64c3d159SToomas Soome crc32_combine() if the generated op is used more than once. 1773*64c3d159SToomas Soome */ 1774*64c3d159SToomas Soome 1775ab9e68a2SToomas Soome 1776ab9e68a2SToomas Soome /* various hacks, don't look :) */ 1777ab9e68a2SToomas Soome 1778ab9e68a2SToomas Soome /* deflateInit and inflateInit are macros to allow checking the zlib version 1779ab9e68a2SToomas Soome * and the compiler's view of z_stream: 1780ab9e68a2SToomas Soome */ 1781ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 1782ab9e68a2SToomas Soome const char *version, int stream_size)); 1783ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 1784ab9e68a2SToomas Soome const char *version, int stream_size)); 1785ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 1786ab9e68a2SToomas Soome int windowBits, int memLevel, 1787ab9e68a2SToomas Soome int strategy, const char *version, 1788ab9e68a2SToomas Soome int stream_size)); 1789ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 1790ab9e68a2SToomas Soome const char *version, int stream_size)); 1791ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 1792ab9e68a2SToomas Soome unsigned char FAR *window, 1793ab9e68a2SToomas Soome const char *version, 1794ab9e68a2SToomas Soome int stream_size)); 1795ab9e68a2SToomas Soome #ifdef Z_PREFIX_SET 1796ab9e68a2SToomas Soome # define z_deflateInit(strm, level) \ 1797ab9e68a2SToomas Soome deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) 1798ab9e68a2SToomas Soome # define z_inflateInit(strm) \ 1799ab9e68a2SToomas Soome inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) 1800ab9e68a2SToomas Soome # define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 1801ab9e68a2SToomas Soome deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 1802ab9e68a2SToomas Soome (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) 1803ab9e68a2SToomas Soome # define z_inflateInit2(strm, windowBits) \ 1804ab9e68a2SToomas Soome inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 1805ab9e68a2SToomas Soome (int)sizeof(z_stream)) 1806ab9e68a2SToomas Soome # define z_inflateBackInit(strm, windowBits, window) \ 1807ab9e68a2SToomas Soome inflateBackInit_((strm), (windowBits), (window), \ 1808ab9e68a2SToomas Soome ZLIB_VERSION, (int)sizeof(z_stream)) 1809ab9e68a2SToomas Soome #else 1810ab9e68a2SToomas Soome # define deflateInit(strm, level) \ 1811ab9e68a2SToomas Soome deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) 1812ab9e68a2SToomas Soome # define inflateInit(strm) \ 1813ab9e68a2SToomas Soome inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) 1814ab9e68a2SToomas Soome # define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 1815ab9e68a2SToomas Soome deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 1816ab9e68a2SToomas Soome (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) 1817ab9e68a2SToomas Soome # define inflateInit2(strm, windowBits) \ 1818ab9e68a2SToomas Soome inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 1819ab9e68a2SToomas Soome (int)sizeof(z_stream)) 1820ab9e68a2SToomas Soome # define inflateBackInit(strm, windowBits, window) \ 1821ab9e68a2SToomas Soome inflateBackInit_((strm), (windowBits), (window), \ 1822ab9e68a2SToomas Soome ZLIB_VERSION, (int)sizeof(z_stream)) 1823ab9e68a2SToomas Soome #endif 1824ab9e68a2SToomas Soome 1825ab9e68a2SToomas Soome #ifndef Z_SOLO 1826ab9e68a2SToomas Soome 1827ab9e68a2SToomas Soome /* gzgetc() macro and its supporting function and exposed data structure. Note 1828ab9e68a2SToomas Soome * that the real internal state is much larger than the exposed structure. 1829ab9e68a2SToomas Soome * This abbreviated structure exposes just enough for the gzgetc() macro. The 1830ab9e68a2SToomas Soome * user should not mess with these exposed elements, since their names or 1831ab9e68a2SToomas Soome * behavior could change in the future, perhaps even capriciously. They can 1832ab9e68a2SToomas Soome * only be used by the gzgetc() macro. You have been warned. 1833ab9e68a2SToomas Soome */ 1834ab9e68a2SToomas Soome struct gzFile_s { 1835ab9e68a2SToomas Soome unsigned have; 1836ab9e68a2SToomas Soome unsigned char *next; 1837ab9e68a2SToomas Soome z_off64_t pos; 1838ab9e68a2SToomas Soome }; 1839ab9e68a2SToomas Soome ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ 1840ab9e68a2SToomas Soome #ifdef Z_PREFIX_SET 1841ab9e68a2SToomas Soome # undef z_gzgetc 1842ab9e68a2SToomas Soome # define z_gzgetc(g) \ 1843ab9e68a2SToomas Soome ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) 1844ab9e68a2SToomas Soome #else 1845ab9e68a2SToomas Soome # define gzgetc(g) \ 1846ab9e68a2SToomas Soome ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) 1847ab9e68a2SToomas Soome #endif 1848ab9e68a2SToomas Soome 1849ab9e68a2SToomas Soome /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or 1850ab9e68a2SToomas Soome * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if 1851ab9e68a2SToomas Soome * both are true, the application gets the *64 functions, and the regular 1852ab9e68a2SToomas Soome * functions are changed to 64 bits) -- in case these are set on systems 1853ab9e68a2SToomas Soome * without large file support, _LFS64_LARGEFILE must also be true 1854ab9e68a2SToomas Soome */ 1855ab9e68a2SToomas Soome #ifdef Z_LARGE64 1856ab9e68a2SToomas Soome ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 1857ab9e68a2SToomas Soome ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 1858ab9e68a2SToomas Soome ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 1859ab9e68a2SToomas Soome ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 1860ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); 1861ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); 1862*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); 1863ab9e68a2SToomas Soome #endif 1864ab9e68a2SToomas Soome 1865ab9e68a2SToomas Soome #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) 1866ab9e68a2SToomas Soome # ifdef Z_PREFIX_SET 1867ab9e68a2SToomas Soome # define z_gzopen z_gzopen64 1868ab9e68a2SToomas Soome # define z_gzseek z_gzseek64 1869ab9e68a2SToomas Soome # define z_gztell z_gztell64 1870ab9e68a2SToomas Soome # define z_gzoffset z_gzoffset64 1871ab9e68a2SToomas Soome # define z_adler32_combine z_adler32_combine64 1872ab9e68a2SToomas Soome # define z_crc32_combine z_crc32_combine64 1873*64c3d159SToomas Soome # define z_crc32_combine_gen z_crc32_combine_gen64 1874ab9e68a2SToomas Soome # else 1875ab9e68a2SToomas Soome # define gzopen gzopen64 1876ab9e68a2SToomas Soome # define gzseek gzseek64 1877ab9e68a2SToomas Soome # define gztell gztell64 1878ab9e68a2SToomas Soome # define gzoffset gzoffset64 1879ab9e68a2SToomas Soome # define adler32_combine adler32_combine64 1880ab9e68a2SToomas Soome # define crc32_combine crc32_combine64 1881*64c3d159SToomas Soome # define crc32_combine_gen crc32_combine_gen64 1882ab9e68a2SToomas Soome # endif 1883ab9e68a2SToomas Soome # ifndef Z_LARGE64 1884ab9e68a2SToomas Soome ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 1885ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); 1886ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); 1887ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); 1888ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 1889ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 1890*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); 1891ab9e68a2SToomas Soome # endif 1892ab9e68a2SToomas Soome #else 1893ab9e68a2SToomas Soome ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 1894ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); 1895ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); 1896ab9e68a2SToomas Soome ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); 1897ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 1898ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1899*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); 1900ab9e68a2SToomas Soome #endif 1901ab9e68a2SToomas Soome 1902ab9e68a2SToomas Soome #else /* Z_SOLO */ 1903ab9e68a2SToomas Soome 1904ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 1905ab9e68a2SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1906*64c3d159SToomas Soome ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); 1907ab9e68a2SToomas Soome 1908ab9e68a2SToomas Soome #endif /* !Z_SOLO */ 1909ab9e68a2SToomas Soome 1910ab9e68a2SToomas Soome /* undocumented functions */ 1911ab9e68a2SToomas Soome ZEXTERN const char * ZEXPORT zError OF((int)); 1912ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); 1913ab9e68a2SToomas Soome ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); 1914ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); 1915ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); 1916ab9e68a2SToomas Soome ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); 1917ab9e68a2SToomas Soome ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); 1918ab9e68a2SToomas Soome ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); 1919*64c3d159SToomas Soome #if defined(_WIN32) && !defined(Z_SOLO) 1920ab9e68a2SToomas Soome ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, 1921ab9e68a2SToomas Soome const char *mode)); 1922ab9e68a2SToomas Soome #endif 1923ab9e68a2SToomas Soome #if defined(STDC) || defined(Z_HAVE_STDARG_H) 1924ab9e68a2SToomas Soome # ifndef Z_SOLO 1925ab9e68a2SToomas Soome ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, 1926ab9e68a2SToomas Soome const char *format, 1927ab9e68a2SToomas Soome va_list va)); 1928ab9e68a2SToomas Soome # endif 1929ab9e68a2SToomas Soome #endif 1930ab9e68a2SToomas Soome 1931ab9e68a2SToomas Soome #ifdef __cplusplus 1932ab9e68a2SToomas Soome } 1933ab9e68a2SToomas Soome #endif 1934ab9e68a2SToomas Soome 1935ab9e68a2SToomas Soome #endif /* ZLIB_H */ 1936