1ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* zlib.h -- interface of the 'zlib' general purpose compression library 2ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease version 1.1.4, March 11th, 2002 3ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 4ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler 5ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 6ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This software is provided 'as-is', without any express or implied 7ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease warranty. In no event will the authors be held liable for any damages 8ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease arising from the use of this software. 9ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 10ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Permission is granted to anyone to use this software for any purpose, 11ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease including commercial applications, and to alter it and redistribute it 12ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease freely, subject to the following restrictions: 13ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 14ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 1. The origin of this software must not be misrepresented; you must not 15ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease claim that you wrote the original software. If you use this software 16ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease in a product, an acknowledgment in the product documentation would be 17ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease appreciated but is not required. 18ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 2. Altered source versions must be plainly marked as such, and must not be 19ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease misrepresented as being the original software. 20ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 3. This notice may not be removed or altered from any source distribution. 21ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 22ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Jean-loup Gailly Mark Adler 23ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease jloup@gzip.org madler@alumni.caltech.edu 24ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 25ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 26ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The data format used by the zlib library is described by RFCs (Request for 27ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt 28ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 29ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 30ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 31ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#ifndef _ZLIB_H 32ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define _ZLIB_H 33ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 34ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#include "zconf.h" 35ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 36ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#ifdef __cplusplus 37ec0bab5697bb31ba980810145f62e3799946ec60Victoria Leaseextern "C" { 38ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#endif 39ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 40ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define ZLIB_VERSION "1.1.4" 41ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 42ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 43ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The 'zlib' compression library provides in-memory compression and 44ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease decompression functions, including integrity checks of the uncompressed 45ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease data. This version of the library supports only one compression method 46ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (deflation) but other algorithms will be added later and will have the same 47ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease stream interface. 48ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 49ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Compression can be done in a single step if the buffers are large 50ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough (for example if an input file is mmap'ed), or can be done by 51ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease repeated calls of the compression function. In the latter case, the 52ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease application must provide more input and/or consume the output 53ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (providing more output space) before each call. 54ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 55ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The library also supports reading and writing files in gzip (.gz) format 56ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease with an interface similar to that of stdio. 57ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 58ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The library does not install any signal handler. The decoder checks 59ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the consistency of the compressed data, so the library should never 60ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease crash even in case of corrupted input. 61ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 62ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 63ec0bab5697bb31ba980810145f62e3799946ec60Victoria Leasetypedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 64ec0bab5697bb31ba980810145f62e3799946ec60Victoria Leasetypedef void (*free_func) OF((voidpf opaque, voidpf address)); 65ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 66ec0bab5697bb31ba980810145f62e3799946ec60Victoria Leasestruct internal_state; 67ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 68ec0bab5697bb31ba980810145f62e3799946ec60Victoria Leasetypedef struct z_stream_s { 69ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Bytef *next_in; /* next input byte */ 70ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uInt avail_in; /* number of bytes available at next_in */ 71ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uLong total_in; /* total nb of input bytes read so far */ 72ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 73ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Bytef *next_out; /* next output byte should be put there */ 74ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uInt avail_out; /* remaining free space at next_out */ 75ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uLong total_out; /* total nb of bytes output so far */ 76ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 77ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease char *msg; /* last error message, NULL if no error */ 78ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease struct internal_state FAR *state; /* not visible by applications */ 79ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 80ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease alloc_func zalloc; /* used to allocate the internal state */ 81ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease free_func zfree; /* used to free the internal state */ 82ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease voidpf opaque; /* private data object passed to zalloc and zfree */ 83ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 84ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int data_type; /* best guess about the data type: ascii or binary */ 85ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uLong adler; /* adler32 value of the uncompressed data */ 86ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uLong reserved; /* reserved for future use */ 87ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease} z_stream; 88ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 89ec0bab5697bb31ba980810145f62e3799946ec60Victoria Leasetypedef z_stream FAR *z_streamp; 90ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 91ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 92ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The application must update next_in and avail_in when avail_in has 93ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease dropped to zero. It must update next_out and avail_out when avail_out 94ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease has dropped to zero. The application must initialize zalloc, zfree and 95ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease opaque before calling the init function. All other fields are set by the 96ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression library and must not be updated by the application. 97ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 98ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The opaque value provided by the application will be passed as the first 99ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease parameter for calls of zalloc and zfree. This can be useful for custom 100ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease memory management. The compression library attaches no meaning to the 101ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease opaque value. 102ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 103ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease zalloc must return Z_NULL if there is not enough memory for the object. 104ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If zlib is used in a multi-threaded application, zalloc and zfree must be 105ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease thread safe. 106ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 107ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease On 16-bit systems, the functions zalloc and zfree must be able to allocate 108ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease exactly 65536 bytes, but will not be required to allocate more than this 109ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 110ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease pointers returned by zalloc for objects of exactly 65536 bytes *must* 111ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease have their offset normalized to zero. The default allocation function 112ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease provided by this library ensures this (see zutil.c). To reduce memory 113ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease requirements and avoid any allocation of 64K objects, at the expense of 114ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 115ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 116ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The fields total_in and total_out can be used for statistics or 117ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease progress reports. After compression, total_in holds the total size of 118ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the uncompressed data and may be saved for use in the decompressor 119ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (particularly if the decompressor wants to decompress everything in 120ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease a single step). 121ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 122ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 123ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease /* constants */ 124ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 125ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_NO_FLUSH 0 126ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 127ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_SYNC_FLUSH 2 128ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_FULL_FLUSH 3 129ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_FINISH 4 130ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* Allowed flush values; see deflate() below for details */ 131ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 132ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_OK 0 133ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_STREAM_END 1 134ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_NEED_DICT 2 135ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_ERRNO (-1) 136ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_STREAM_ERROR (-2) 137ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_DATA_ERROR (-3) 138ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_MEM_ERROR (-4) 139ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_BUF_ERROR (-5) 140ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_VERSION_ERROR (-6) 141ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* Return codes for the compression/decompression functions. Negative 142ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease * values are errors, positive values are used for special but normal events. 143ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease */ 144ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 145ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_NO_COMPRESSION 0 146ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_BEST_SPEED 1 147ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_BEST_COMPRESSION 9 148ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_DEFAULT_COMPRESSION (-1) 149ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* compression levels */ 150ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 151ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_FILTERED 1 152ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_HUFFMAN_ONLY 2 153ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_DEFAULT_STRATEGY 0 154ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* compression strategy; see deflateInit2() below for details */ 155ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 156ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_BINARY 0 157ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_ASCII 1 158ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_UNKNOWN 2 159ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* Possible values of the data_type field */ 160ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 161ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_DEFLATED 8 162ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* The deflate compression method (the only one supported in this version) */ 163ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 164ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 165ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 166ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 167ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease /* basic functions */ 168ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 169ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 170ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If the first character differs, the library code actually used is 171ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease not compatible with the zlib.h header file used by the application. 172ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This check is automatically made by deflateInit and inflateInit. 173ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease */ 174ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 175ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 176ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) deflateInit OF((z_streamp strm, int level)); 177ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 178ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Initializes the internal stream state for compression. The fields 179ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease zalloc, zfree and opaque must be initialized before by the caller. 180ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If zalloc and zfree are set to Z_NULL, deflateInit updates them to 181ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease use default allocation functions. 182ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 183ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 184ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 1 gives best speed, 9 gives best compression, 0 gives no compression at 185ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease all (the input data is simply copied a block at a time). 186ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_DEFAULT_COMPRESSION requests a default compromise between speed and 187ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression (currently equivalent to level 6). 188ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 189ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 190ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough memory, Z_STREAM_ERROR if level is not a valid compression level, 191ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 192ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease with the version assumed by the caller (ZLIB_VERSION). 193ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease msg is set to null if there is no error message. deflateInit does not 194ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease perform any compression: this will be done by deflate(). 195ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 196ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 197ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 198ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 199ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflate compresses as much data as possible, and stops when the input 200ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease buffer becomes empty or the output buffer becomes full. It may introduce some 201ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease output latency (reading input without producing any output) except when 202ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease forced to flush. 203ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 204ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The detailed semantics are as follows. deflate performs one or both of the 205ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease following actions: 206ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 207ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease - Compress more input starting at next_in and update next_in and avail_in 208ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease accordingly. If not all input can be processed (because there is not 209ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough room in the output buffer), next_in and avail_in are updated and 210ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease processing will resume at this point for the next call of deflate(). 211ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 212ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease - Provide more output starting at next_out and update next_out and avail_out 213ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease accordingly. This action is forced if the parameter flush is non zero. 214ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Forcing flush frequently degrades the compression ratio, so this parameter 215ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease should be set only when necessary (in interactive applications). 216ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Some output may be provided even if flush is not set. 217ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 218ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Before the call of deflate(), the application should ensure that at least 219ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease one of the actions is possible, by providing more input and/or consuming 220ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease more output, and updating avail_in or avail_out accordingly; avail_out 221ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease should never be zero before the call. The application can consume the 222ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compressed output when it wants, for example when the output buffer is full 223ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 224ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease and with zero avail_out, it must be called again after making room in the 225ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease output buffer because there might be more output pending. 226ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 227ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 228ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease flushed to the output buffer and the output is aligned on a byte boundary, so 229ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease that the decompressor can get all input data available so far. (In particular 230ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease avail_in is zero after the call if enough output space has been provided 231ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease before the call.) Flushing may degrade compression for some compression 232ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease algorithms and so it should be used only when necessary. 233ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 234ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If flush is set to Z_FULL_FLUSH, all output is flushed as with 235ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_SYNC_FLUSH, and the compression state is reset so that decompression can 236ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease restart from this point if previous compressed data has been damaged or if 237ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 238ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the compression. 239ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 240ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If deflate returns with avail_out == 0, this function must be called again 241ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease with the same value of the flush parameter and more output space (updated 242ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease avail_out), until the flush is complete (deflate returns with non-zero 243ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease avail_out). 244ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 245ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If the parameter flush is set to Z_FINISH, pending input is processed, 246ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease pending output is flushed and deflate returns with Z_STREAM_END if there 247ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease was enough output space; if deflate returns with Z_OK, this function must be 248ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease called again with Z_FINISH and more output space (updated avail_out) but no 249ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease more input data, until it returns with Z_STREAM_END or an error. After 250ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflate has returned Z_STREAM_END, the only possible operations on the 251ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease stream are deflateReset or deflateEnd. 252ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 253ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_FINISH can be used immediately after deflateInit if all the compression 254ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease is to be done in a single step. In this case, avail_out must be at least 255ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 0.1% larger than avail_in plus 12 bytes. If deflate does not return 256ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_STREAM_END, then it must be called again as described above. 257ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 258ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflate() sets strm->adler to the adler32 checksum of all input read 259ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease so far (that is, total_in bytes). 260ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 261ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflate() may update data_type if it can make a good guess about 262ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered 263ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease binary. This field is only for information purposes and does not affect 264ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the compression algorithm in any manner. 265ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 266ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflate() returns Z_OK if some progress has been made (more input 267ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease processed or more output produced), Z_STREAM_END if all input has been 268ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease consumed and all output has been produced (only when flush is set to 269ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 270ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 271ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (for example avail_in or avail_out was zero). 272ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 273ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 274ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 275ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 276ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease All dynamically allocated data structures for this stream are freed. 277ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function discards any unprocessed input and does not flush any 278ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease pending output. 279ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 280ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 281ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease stream state was inconsistent, Z_DATA_ERROR if the stream was freed 282ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease prematurely (some input or output was discarded). In the error case, 283ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease msg may be set but then points to a static string (which must not be 284ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deallocated). 285ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 286ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 287ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 288ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 289ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) inflateInit OF((z_streamp strm)); 290ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 291ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Initializes the internal stream state for decompression. The fields 292ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease next_in, avail_in, zalloc, zfree and opaque must be initialized before by 293ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 294ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease value depends on the compression method), inflateInit determines the 295ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression method from the zlib header and allocates all data structures 296ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease accordingly; otherwise the allocation will be deferred to the first call of 297ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 298ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease use default allocation functions. 299ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 300ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 301ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 302ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease version assumed by the caller. msg is set to null if there is no error 303ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease message. inflateInit does not perform any decompression apart from reading 304ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the zlib header if present: this will be done by inflate(). (So next_in and 305ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease avail_in may be modified, but next_out and avail_out are unchanged.) 306ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 307ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 308ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 309ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) inflate OF((z_streamp strm, int flush)); 310ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 311ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflate decompresses as much data as possible, and stops when the input 312ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease buffer becomes empty or the output buffer becomes full. It may some 313ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease introduce some output latency (reading input without producing any output) 314ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease except when forced to flush. 315ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 316ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The detailed semantics are as follows. inflate performs one or both of the 317ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease following actions: 318ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 319ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease - Decompress more input starting at next_in and update next_in and avail_in 320ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease accordingly. If not all input can be processed (because there is not 321ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough room in the output buffer), next_in is updated and processing 322ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease will resume at this point for the next call of inflate(). 323ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 324ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease - Provide more output starting at next_out and update next_out and avail_out 325ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease accordingly. inflate() provides as much output as possible, until there 326ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease is no more input data or no more space in the output buffer (see below 327ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease about the flush parameter). 328ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 329ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Before the call of inflate(), the application should ensure that at least 330ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease one of the actions is possible, by providing more input and/or consuming 331ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease more output, and updating the next_* and avail_* values accordingly. 332ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The application can consume the uncompressed output when it wants, for 333ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease example when the output buffer is full (avail_out == 0), or after each 334ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease call of inflate(). If inflate returns Z_OK and with zero avail_out, it 335ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease must be called again after making room in the output buffer because there 336ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease might be more output pending. 337ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 338ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much 339ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease output as possible to the output buffer. The flushing behavior of inflate is 340ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease not specified for values of the flush parameter other than Z_SYNC_FLUSH 341ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease and Z_FINISH, but the current implementation actually flushes as much output 342ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease as possible anyway. 343ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 344ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflate() should normally be called until it returns Z_STREAM_END or an 345ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease error. However if all decompression is to be performed in a single step 346ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (a single call of inflate), the parameter flush should be set to 347ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_FINISH. In this case all pending input is processed and all pending 348ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease output is flushed; avail_out must be large enough to hold all the 349ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uncompressed data. (The size of the uncompressed data may have been saved 350ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease by the compressor for this purpose.) The next operation on this stream must 351ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease be inflateEnd to deallocate the decompression state. The use of Z_FINISH 352ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease is never required, but can be used to inform inflate that a faster routine 353ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease may be used for the single inflate() call. 354ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 355ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If a preset dictionary is needed at this point (see inflateSetDictionary 356ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease below), inflate sets strm-adler to the adler32 checksum of the 357ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise 358ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease it sets strm->adler to the adler32 checksum of all output produced 359ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or 360ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease an error code as described below. At the end of the stream, inflate() 361ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease checks that its computed adler32 checksum is equal to that saved by the 362ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compressor and returns Z_STREAM_END only if the checksum is correct. 363ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 364ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflate() returns Z_OK if some progress has been made (more input processed 365ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease or more output produced), Z_STREAM_END if the end of the compressed data has 366ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease been reached and all uncompressed output has been produced, Z_NEED_DICT if a 367ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 368ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease corrupted (input stream not conforming to the zlib format or incorrect 369ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent 370ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not 371ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough memory, Z_BUF_ERROR if no progress is possible or if there was not 372ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR 373ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease case, the application may then call inflateSync to look for a good 374ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression block. 375ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 376ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 377ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 378ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) inflateEnd OF((z_streamp strm)); 379ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 380ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease All dynamically allocated data structures for this stream are freed. 381ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function discards any unprocessed input and does not flush any 382ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease pending output. 383ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 384ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 385ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease was inconsistent. In the error case, msg may be set but then points to a 386ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease static string (which must not be deallocated). 387ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 388ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 389ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease /* Advanced functions */ 390ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 391ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 392ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The following functions are needed only in some special applications. 393ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 394ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 395ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 396ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) deflateInit2 OF((z_streamp strm, 397ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int level, 398ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int method, 399ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int windowBits, 400ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int memLevel, 401ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int strategy)); 402ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 403ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This is another version of deflateInit with more compression options. The 404ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease fields next_in, zalloc, zfree and opaque must be initialized before by 405ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the caller. 406ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 407ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The method parameter is the compression method. It must be Z_DEFLATED in 408ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease this version of the library. 409ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 410ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The windowBits parameter is the base two logarithm of the window size 411ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (the size of the history buffer). It should be in the range 8..15 for this 412ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease version of the library. Larger values of this parameter result in better 413ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression at the expense of memory usage. The default value is 15 if 414ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateInit is used instead. 415ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 416ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The memLevel parameter specifies how much memory should be allocated 417ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease for the internal compression state. memLevel=1 uses minimum memory but 418ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease is slow and reduces compression ratio; memLevel=9 uses maximum memory 419ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease for optimal speed. The default value is 8. See zconf.h for total memory 420ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease usage as a function of windowBits and memLevel. 421ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 422ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The strategy parameter is used to tune the compression algorithm. Use the 423ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 424ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no 425ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease string match). Filtered data consists mostly of small values with a 426ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease somewhat random distribution. In this case, the compression algorithm is 427ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease tuned to compress them better. The effect of Z_FILTERED is to force more 428ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Huffman coding and less string matching; it is somewhat intermediate 429ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects 430ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the compression ratio but not the correctness of the compressed output even 431ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if it is not set appropriately. 432ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 433ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 434ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 435ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease method). msg is set to null if there is no error message. deflateInit2 does 436ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease not perform any compression: this will be done by deflate(). 437ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 438ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 439ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 440ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Initializes the compression dictionary from the given byte sequence 441ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease without producing any compressed output. This function must be called 442ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease immediately after deflateInit, deflateInit2 or deflateReset, before any 443ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease call of deflate. The compressor and decompressor must use exactly the same 444ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease dictionary (see inflateSetDictionary). 445ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 446ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The dictionary should consist of strings (byte sequences) that are likely 447ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease to be encountered later in the data to be compressed, with the most commonly 448ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease used strings preferably put towards the end of the dictionary. Using a 449ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease dictionary is most useful when the data to be compressed is short and can be 450ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease predicted with good accuracy; the data can then be compressed better than 451ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease with the default empty dictionary. 452ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 453ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Depending on the size of the compression data structures selected by 454ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateInit or deflateInit2, a part of the dictionary may in effect be 455ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease discarded, for example if the dictionary is larger than the window size in 456ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflate or deflate2. Thus the strings most likely to be useful should be 457ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease put at the end of the dictionary, not at the front. 458ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 459ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Upon return of this function, strm->adler is set to the Adler32 value 460ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease of the dictionary; the decompressor may later use this value to determine 461ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease which dictionary has been used by the compressor. (The Adler32 value 462ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease applies to the whole dictionary even if only a subset of the dictionary is 463ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease actually used by the compressor.) 464ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 465ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 466ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease parameter is invalid (such as NULL dictionary) or the stream state is 467ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inconsistent (for example if deflate has already been called for this stream 468ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease or if the compression method is bsort). deflateSetDictionary does not 469ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease perform any compression: this will be done by deflate(). 470ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 471ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 472ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 473ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Sets the destination stream as a complete copy of the source stream. 474ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 475ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function can be useful when several compression strategies will be 476ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease tried, for example when there are several ways of pre-processing the input 477ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease data with a filter. The streams that will be discarded should then be freed 478ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease by calling deflateEnd. Note that deflateCopy duplicates the internal 479ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression state which can be quite large, so this strategy is slow and 480ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease can consume lots of memory. 481ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 482ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 483ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 484ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (such as zalloc being NULL). msg is left unchanged in both source and 485ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease destination. 486ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 487ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 488ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 489ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function is equivalent to deflateEnd followed by deflateInit, 490ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease but does not free and reallocate all the internal compression state. 491ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The stream will keep the same compression level and any other attributes 492ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease that may have been set by deflateInit2. 493ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 494ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 495ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease stream state was inconsistent (such as zalloc or state being NULL). 496ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 497ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 498ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 499ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Dynamically update the compression level and compression strategy. The 500ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease interpretation of level and strategy is as in deflateInit2. This can be 501ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease used to switch between compression and straight copy of the input data, or 502ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease to switch to a different kind of input data requiring a different 503ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease strategy. If the compression level is changed, the input available so far 504ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease is compressed with the old level (and may be flushed); the new level will 505ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease take effect only at the next call of deflate(). 506ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 507ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Before the call of deflateParams, the stream state must be set as for 508ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease a call of deflate(), since the currently available input may have to 509ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease be compressed and flushed. In particular, strm->avail_out must be non-zero. 510ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 511ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 512ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 513ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if strm->avail_out was zero. 514ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 515ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 516ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 517ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) inflateInit2 OF((z_streamp strm, 518ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease int windowBits)); 519ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 520ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This is another version of inflateInit with an extra parameter. The 521ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease fields next_in, avail_in, zalloc, zfree and opaque must be initialized 522ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease before by the caller. 523ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 524ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The windowBits parameter is the base two logarithm of the maximum window 525ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease size (the size of the history buffer). It should be in the range 8..15 for 526ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease this version of the library. The default value is 15 if inflateInit is used 527ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease instead. If a compressed stream with a larger window size is given as 528ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease input, inflate() will return with the error code Z_DATA_ERROR instead of 529ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease trying to allocate a larger window. 530ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 531ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 532ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative 533ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease memLevel). msg is set to null if there is no error message. inflateInit2 534ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease does not perform any decompression apart from reading the zlib header if 535ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease present: this will be done by inflate(). (So next_in and avail_in may be 536ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease modified, but next_out and avail_out are unchanged.) 537ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 538ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 539ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 540ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Initializes the decompression dictionary from the given uncompressed byte 541ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease sequence. This function must be called immediately after a call of inflate 542ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if this call returned Z_NEED_DICT. The dictionary chosen by the compressor 543ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease can be determined from the Adler32 value returned by this call of 544ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflate. The compressor and decompressor must use exactly the same 545ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease dictionary (see deflateSetDictionary). 546ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 547ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 548ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease parameter is invalid (such as NULL dictionary) or the stream state is 549ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 550ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease expected one (incorrect Adler32 value). inflateSetDictionary does not 551ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease perform any decompression: this will be done by subsequent calls of 552ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflate(). 553ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 554ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 555ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 556ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Skips invalid compressed data until a full flush point (see above the 557ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease description of deflate with Z_FULL_FLUSH) can be found, or until all 558ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease available input is skipped. No output is provided. 559ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 560ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 561ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if no more input was provided, Z_DATA_ERROR if no flush point has been found, 562ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 563ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease case, the application may save the current current value of total_in which 564ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease indicates where valid compressed data was found. In the error case, the 565ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease application may repeatedly call inflateSync, providing more input each time, 566ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease until success or end of the input data. 567ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 568ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 569ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) inflateReset OF((z_streamp strm)); 570ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 571ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function is equivalent to inflateEnd followed by inflateInit, 572ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease but does not free and reallocate all the internal decompression state. 573ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The stream will keep attributes that may have been set by inflateInit2. 574ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 575ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 576ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease stream state was inconsistent (such as zalloc or state being NULL). 577ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 578ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 579ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 580ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease /* utility functions */ 581ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 582ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 583ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The following utility functions are implemented on top of the 584ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease basic stream-oriented functions. To simplify the interface, some 585ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease default options are assumed (compression level and memory usage, 586ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease standard memory allocation functions). The source code of these 587ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease utility functions can easily be modified if you need special options. 588ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 589ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 590ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 591ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Compresses the source buffer into the destination buffer. sourceLen is 592ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the byte length of the source buffer. Upon entry, destLen is the total 593ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease size of the destination buffer, which must be at least 0.1% larger than 594ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the 595ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compressed buffer. 596ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function can be used to compress a whole file at once if the 597ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease input file is mmap'ed. 598ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compress returns Z_OK if success, Z_MEM_ERROR if there was not 599ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough memory, Z_BUF_ERROR if there was not enough room in the output 600ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease buffer. 601ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 602ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 603ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 604ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Compresses the source buffer into the destination buffer. The level 605ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease parameter has the same meaning as in deflateInit. sourceLen is the byte 606ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease length of the source buffer. Upon entry, destLen is the total size of the 607ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease destination buffer, which must be at least 0.1% larger than sourceLen plus 608ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 609ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 610ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 611ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease memory, Z_BUF_ERROR if there was not enough room in the output buffer, 612ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Z_STREAM_ERROR if the level parameter is invalid. 613ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 614ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 615ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 616ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Decompresses the source buffer into the destination buffer. sourceLen is 617ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the byte length of the source buffer. Upon entry, destLen is the total 618ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease size of the destination buffer, which must be large enough to hold the 619ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease entire uncompressed data. (The size of the uncompressed data must have 620ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease been saved previously by the compressor and transmitted to the decompressor 621ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease by some mechanism outside the scope of this compression library.) 622ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Upon exit, destLen is the actual size of the compressed buffer. 623ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease This function can be used to decompress a whole file at once if the 624ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease input file is mmap'ed. 625ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 626ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 627ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease enough memory, Z_BUF_ERROR if there was not enough room in the output 628ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease buffer, or Z_DATA_ERROR if the input data was corrupted. 629ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 630ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 631ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 632ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 633ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Opens a gzip (.gz) file for reading or writing. The mode parameter 634ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease is as in fopen ("rb" or "wb") but can also include a compression level 635ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 636ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Huffman only compression as in "wb1h". (See the description 637ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease of deflateInit2 for more information about the strategy parameter.) 638ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 639ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzopen can be used to read a file which is not in gzip format; in this 640ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease case gzread will directly read from the file without decompression. 641ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 642ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzopen returns NULL if the file could not be opened or if there was 643ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease insufficient memory to allocate the (de)compression state; errno 644ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease can be checked to distinguish the two cases (if errno is zero, the 645ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease zlib error is Z_MEM_ERROR). */ 646ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 647ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 648ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzdopen() associates a gzFile with the file descriptor fd. File 649ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease descriptors are obtained from calls like open, dup, creat, pipe or 650ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease fileno (in the file has been previously opened with fopen). 651ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The mode parameter is as in gzopen. 652ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease The next call of gzclose on the returned gzFile will also close the 653ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 654ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 655ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzdopen returns NULL if there was insufficient memory to allocate 656ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the (de)compression state. 657ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 658ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 659ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 660ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Dynamically update the compression level or strategy. See the description 661ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease of deflateInit2 for the meaning of these parameters. 662ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 663ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease opened for writing. 664ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 665ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 666ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 667ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Reads the given number of uncompressed bytes from the compressed file. 668ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If the input file was not in gzip format, gzread copies the given number 669ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease of bytes into the buffer. 670ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzread returns the number of uncompressed bytes actually read (0 for 671ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease end of file, -1 for error). */ 672ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 673ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 674ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Writes the given number of uncompressed bytes into the compressed file. 675ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzwrite returns the number of uncompressed bytes actually written 676ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (0 in case of error). 677ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 678ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 679ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 680ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Converts, formats, and writes the args to the compressed file under 681ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease control of the format string, as in fprintf. gzprintf returns the number of 682ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uncompressed bytes actually written (0 in case of error). 683ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 684ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 685ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 686ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Writes the given null-terminated string to the compressed file, excluding 687ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the terminating null character. 688ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzputs returns the number of characters written, or -1 in case of error. 689ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 690ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 691ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 692ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Reads bytes from the compressed file until len-1 characters are read, or 693ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease a newline character is read and transferred to buf, or an end-of-file 694ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease condition is encountered. The string is then terminated with a null 695ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease character. 696ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzgets returns buf, or Z_NULL in case of error. 697ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 698ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 699ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 700ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Writes c, converted to an unsigned char, into the compressed file. 701ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzputc returns the value that was written, or -1 in case of error. 702ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 703ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 704ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 705ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Reads one byte from the compressed file. gzgetc returns this byte 706ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease or -1 in case of end of file or error. 707ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 708ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 709ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 710ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Flushes all pending output into the compressed file. The parameter 711ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease flush is as in the deflate() function. The return value is the zlib 712ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease error number (see function gzerror below). gzflush returns Z_OK if 713ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the flush parameter is Z_FINISH and all output could be flushed. 714ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzflush should be called only when strictly necessary because it can 715ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease degrade compression. 716ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 717ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 718ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 719ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Sets the starting position for the next gzread or gzwrite on the 720ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease given compressed file. The offset represents a number of bytes in the 721ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uncompressed data stream. The whence parameter is defined as in lseek(2); 722ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the value SEEK_END is not supported. 723ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease If the file is opened for reading, this function is emulated but can be 724ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease extremely slow. If the file is opened for writing, only forward seeks are 725ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease supported; gzseek then compresses a sequence of zeroes up to the new 726ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease starting position. 727ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 728ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzseek returns the resulting offset location as measured in bytes from 729ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the beginning of the uncompressed stream, or -1 in case of error, in 730ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease particular if the file is opened for writing and the new starting position 731ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease would be before the current position. 732ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 733ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 734ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 735ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Rewinds the given file. This function is supported only for reading. 736ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 737ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 738ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 739ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 740ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 741ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Returns the starting position for the next gzread or gzwrite on the 742ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease given compressed file. This position represents a number of bytes in the 743ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uncompressed data stream. 744ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 745ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 746ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 747ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 748ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 749ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Returns 1 when EOF has previously been detected reading the given 750ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease input stream, otherwise zero. 751ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 752ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 753ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 754ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Flushes all pending output if necessary, closes the compressed file 755ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease and deallocates all the (de)compression state. The return value is the zlib 756ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease error number (see function gzerror below). 757ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 758ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 759ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 760ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Returns the error message for the last error which occurred on the 761ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease given compressed file. errnum is set to zlib error number. If an 762ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease error occurred in the file system and not in the compression library, 763ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease errnum is set to Z_ERRNO and the application may consult errno 764ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease to get the exact error code. 765ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 766ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 767ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease /* checksum functions */ 768ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 769ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 770ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease These functions are not related to compression but are exported 771ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease anyway because they might be useful in applications using the 772ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease compression library. 773ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 774ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 775ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(uLong) adler32 OF((uLong adler, const Bytef *buf, uInt len)); 776ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 777ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 778ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Update a running Adler-32 checksum with the bytes buf[0..len-1] and 779ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease return the updated checksum. If buf is NULL, this function returns 780ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease the required initial value for the checksum. 781ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 782ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease much faster. Usage example: 783ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 784ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uLong adler = adler32(0L, Z_NULL, 0); 785ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 786ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease while (read_buffer(buffer, length) != EOF) { 787ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease adler = adler32(adler, buffer, length); 788ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease } 789ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if (adler != original_adler) error(); 790ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 791ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 792ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* 793ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Update a running crc with the bytes buf[0..len-1] and return the updated 794ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease crc. If buf is NULL, this function returns the required initial value 795ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease for the crc. Pre- and post-conditioning (one's complement) is performed 796ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease within this function so it shouldn't be done by the application. 797ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease Usage example: 798ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 799ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease uLong crc = crc32(0L, Z_NULL, 0); 800ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 801ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease while (read_buffer(buffer, length) != EOF) { 802ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease crc = crc32(crc, buffer, length); 803ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease } 804ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease if (crc != original_crc) error(); 805ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease*/ 806ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 807ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 808ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease /* various hacks, don't look :) */ 809ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 810ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease/* deflateInit and inflateInit are macros to allow checking the zlib version 811ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease * and the compiler's view of z_stream: 812ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease */ 813ec0bab5697bb31ba980810145f62e3799946ec60Victoria LeaseZEXTERN(int) inflateInit2_ OF((z_streamp strm, int windowBits, 814ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease const char *version, int stream_size)); 815ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define deflateInit(strm, level) \ 816ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 817ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define inflateInit(strm) \ 818ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 819ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 820ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 821ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease (strategy), ZLIB_VERSION, sizeof(z_stream)) 822ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#define inflateInit2(strm, windowBits) \ 823ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 824ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 825ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 826ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#ifdef __cplusplus 827ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease} 828ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#endif 829ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease 830ec0bab5697bb31ba980810145f62e3799946ec60Victoria Lease#endif /* _ZLIB_H */ 831