10a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* zlib.h -- interface of the 'zlib' general purpose compression library 20a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath version 1.2.3, July 18th, 2005 30a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 40a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler 50a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 60a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This software is provided 'as-is', without any express or implied 70a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath warranty. In no event will the authors be held liable for any damages 80a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath arising from the use of this software. 90a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Permission is granted to anyone to use this software for any purpose, 110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath including commercial applications, and to alter it and redistribute it 120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath freely, subject to the following restrictions: 130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1. The origin of this software must not be misrepresented; you must not 150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath claim that you wrote the original software. If you use this software 160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath in a product, an acknowledgment in the product documentation would be 170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath appreciated but is not required. 180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2. Altered source versions must be plainly marked as such, and must not be 190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath misrepresented as being the original software. 200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3. This notice may not be removed or altered from any source distribution. 210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Jean-loup Gailly Mark Adler 230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath jloup@gzip.org madler@alumni.caltech.edu 240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The data format used by the zlib library is described by RFCs (Request for 270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt 280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#ifndef ZLIB_H 320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define ZLIB_H 330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#include "zconf.h" 350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#ifdef __cplusplus 370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathextern "C" { 380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#endif 390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define ZLIB_VERSION "1.2.3" 410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define ZLIB_VERNUM 0x1230 420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The 'zlib' compression library provides in-memory compression and 450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath decompression functions, including integrity checks of the uncompressed 460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath data. This version of the library supports only one compression method 470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (deflation) but other algorithms will be added later and will have the same 480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream interface. 490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Compression can be done in a single step if the buffers are large 510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough (for example if an input file is mmap'ed), or can be done by 520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath repeated calls of the compression function. In the latter case, the 530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath application must provide more input and/or consume the output 540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (providing more output space) before each call. 550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The compressed data format used by default by the in-memory functions is 570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath around a deflate stream, which is itself documented in RFC 1951. 590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The library also supports reading and writing files in gzip (.gz) format 610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath with an interface similar to that of stdio using the functions that start 620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath with "gz". The gzip format is different from the zlib format. gzip is a 630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This library can optionally read and write gzip streams in memory as well. 660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The zlib format was designed to be compact and fast for use in memory 680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and on communications channels. The gzip format was designed for single- 690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath file compression on file systems, has a larger header than zlib to maintain 700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath directory information, and uses a different, slower check method than zlib. 710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The library does not install any signal handler. The decoder checks 730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the consistency of the compressed data, so the library should never 740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath crash even in case of corrupted input. 750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef void (*free_func) OF((voidpf opaque, voidpf address)); 790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathstruct internal_state; 810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef struct z_stream_s { 830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Bytef *next_in; /* next input byte */ 840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt avail_in; /* number of bytes available at next_in */ 850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong total_in; /* total nb of input bytes read so far */ 860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Bytef *next_out; /* next output byte should be put there */ 880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt avail_out; /* remaining free space at next_out */ 890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong total_out; /* total nb of bytes output so far */ 900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath char *msg; /* last error message, NULL if no error */ 920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath struct internal_state FAR *state; /* not visible by applications */ 930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath alloc_func zalloc; /* used to allocate the internal state */ 950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath free_func zfree; /* used to free the internal state */ 960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath voidpf opaque; /* private data object passed to zalloc and zfree */ 970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int data_type; /* best guess about the data type: binary or text */ 990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong adler; /* adler32 value of the uncompressed data */ 1000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong reserved; /* reserved for future use */ 1010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath} z_stream; 1020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef z_stream FAR *z_streamp; 1040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 1060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzip header information passed to and from zlib routines. See RFC 1952 1070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath for more details on the meanings of these fields. 1080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 1090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef struct gz_header_s { 1100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int text; /* true if compressed data believed to be text */ 1110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong time; /* modification time */ 1120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int xflags; /* extra flags (not used when writing a gzip file) */ 1130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int os; /* operating system */ 1140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Bytef *extra; /* pointer to extra field or Z_NULL if none */ 1150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 1160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt extra_max; /* space at extra (only when reading header) */ 1170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 1180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt name_max; /* space at name (only when reading header) */ 1190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 1200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt comm_max; /* space at comment (only when reading header) */ 1210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int hcrc; /* true if there was or will be a header crc */ 1220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int done; /* true when done reading gzip header (not used 1230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath when writing a gzip file) */ 1240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath} gz_header; 1250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef gz_header FAR *gz_headerp; 1270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 1290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The application must update next_in and avail_in when avail_in has 1300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath dropped to zero. It must update next_out and avail_out when avail_out 1310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath has dropped to zero. The application must initialize zalloc, zfree and 1320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath opaque before calling the init function. All other fields are set by the 1330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression library and must not be updated by the application. 1340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The opaque value provided by the application will be passed as the first 1360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath parameter for calls of zalloc and zfree. This can be useful for custom 1370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath memory management. The compression library attaches no meaning to the 1380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath opaque value. 1390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath zalloc must return Z_NULL if there is not enough memory for the object. 1410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If zlib is used in a multi-threaded application, zalloc and zfree must be 1420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath thread safe. 1430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath On 16-bit systems, the functions zalloc and zfree must be able to allocate 1450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath exactly 65536 bytes, but will not be required to allocate more than this 1460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 1470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath pointers returned by zalloc for objects of exactly 65536 bytes *must* 1480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath have their offset normalized to zero. The default allocation function 1490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath provided by this library ensures this (see zutil.c). To reduce memory 1500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath requirements and avoid any allocation of 64K objects, at the expense of 1510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 1520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The fields total_in and total_out can be used for statistics or 1540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath progress reports. After compression, total_in holds the total size of 1550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the uncompressed data and may be saved for use in the decompressor 1560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (particularly if the decompressor wants to decompress everything in 1570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath a single step). 1580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 1590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath /* constants */ 1610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_NO_FLUSH 0 1630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 1640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_SYNC_FLUSH 2 1650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_FULL_FLUSH 3 1660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_FINISH 4 1670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_BLOCK 5 1680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* Allowed flush values; see deflate() and inflate() below for details */ 1690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_OK 0 1710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_STREAM_END 1 1720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_NEED_DICT 2 1730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_ERRNO (-1) 1740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_STREAM_ERROR (-2) 1750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_DATA_ERROR (-3) 1760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_MEM_ERROR (-4) 1770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_BUF_ERROR (-5) 1780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_VERSION_ERROR (-6) 1790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* Return codes for the compression/decompression functions. Negative 1800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath * values are errors, positive values are used for special but normal events. 1810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath */ 1820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_NO_COMPRESSION 0 1840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_BEST_SPEED 1 1850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_BEST_COMPRESSION 9 1860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_DEFAULT_COMPRESSION (-1) 1870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* compression levels */ 1880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_FILTERED 1 1900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_HUFFMAN_ONLY 2 1910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_RLE 3 1920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_FIXED 4 1930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_DEFAULT_STRATEGY 0 1940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* compression strategy; see deflateInit2() below for details */ 1950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_BINARY 0 1970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_TEXT 1 1980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 1990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_UNKNOWN 2 2000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* Possible values of the data_type field (though see inflate()) */ 2010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_DEFLATED 8 2030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* The deflate compression method (the only one supported in this version) */ 2040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 2060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define zlib_version zlibVersion() 2080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* for compatibility with versions < 1.0.2 */ 2090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath /* basic functions */ 2110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN const char * ZEXPORT zlibVersion OF((void)); 2130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 2140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If the first character differs, the library code actually used is 2150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath not compatible with the zlib.h header file used by the application. 2160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This check is automatically made by deflateInit and inflateInit. 2170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath */ 2180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 2200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 2210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Initializes the internal stream state for compression. The fields 2230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath zalloc, zfree and opaque must be initialized before by the caller. 2240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If zalloc and zfree are set to Z_NULL, deflateInit updates them to 2250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath use default allocation functions. 2260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 2280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1 gives best speed, 9 gives best compression, 0 gives no compression at 2290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath all (the input data is simply copied a block at a time). 2300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_DEFAULT_COMPRESSION requests a default compromise between speed and 2310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression (currently equivalent to level 6). 2320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 2340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough memory, Z_STREAM_ERROR if level is not a valid compression level, 2350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 2360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath with the version assumed by the caller (ZLIB_VERSION). 2370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath msg is set to null if there is no error message. deflateInit does not 2380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath perform any compression: this will be done by deflate(). 2390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 2400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 2430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 2440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate compresses as much data as possible, and stops when the input 2450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath buffer becomes empty or the output buffer becomes full. It may introduce some 2460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath output latency (reading input without producing any output) except when 2470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath forced to flush. 2480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The detailed semantics are as follows. deflate performs one or both of the 2500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath following actions: 2510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath - Compress more input starting at next_in and update next_in and avail_in 2530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath accordingly. If not all input can be processed (because there is not 2540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough room in the output buffer), next_in and avail_in are updated and 2550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath processing will resume at this point for the next call of deflate(). 2560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath - Provide more output starting at next_out and update next_out and avail_out 2580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath accordingly. This action is forced if the parameter flush is non zero. 2590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Forcing flush frequently degrades the compression ratio, so this parameter 2600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath should be set only when necessary (in interactive applications). 2610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Some output may be provided even if flush is not set. 2620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Before the call of deflate(), the application should ensure that at least 2640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath one of the actions is possible, by providing more input and/or consuming 2650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath more output, and updating avail_in or avail_out accordingly; avail_out 2660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath should never be zero before the call. The application can consume the 2670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressed output when it wants, for example when the output buffer is full 2680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 2690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and with zero avail_out, it must be called again after making room in the 2700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath output buffer because there might be more output pending. 2710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 2730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath decide how much data to accumualte before producing output, in order to 2740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath maximize compression. 2750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 2770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath flushed to the output buffer and the output is aligned on a byte boundary, so 2780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath that the decompressor can get all input data available so far. (In particular 2790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath avail_in is zero after the call if enough output space has been provided 2800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath before the call.) Flushing may degrade compression for some compression 2810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath algorithms and so it should be used only when necessary. 2820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If flush is set to Z_FULL_FLUSH, all output is flushed as with 2840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_SYNC_FLUSH, and the compression state is reset so that decompression can 2850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath restart from this point if previous compressed data has been damaged or if 2860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 2870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression. 2880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If deflate returns with avail_out == 0, this function must be called again 2900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath with the same value of the flush parameter and more output space (updated 2910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath avail_out), until the flush is complete (deflate returns with non-zero 2920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 2930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath avail_out is greater than six to avoid repeated flush markers due to 2940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath avail_out == 0 on return. 2950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 2960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If the parameter flush is set to Z_FINISH, pending input is processed, 2970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath pending output is flushed and deflate returns with Z_STREAM_END if there 2980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath was enough output space; if deflate returns with Z_OK, this function must be 2990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath called again with Z_FINISH and more output space (updated avail_out) but no 3000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath more input data, until it returns with Z_STREAM_END or an error. After 3010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate has returned Z_STREAM_END, the only possible operations on the 3020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream are deflateReset or deflateEnd. 3030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_FINISH can be used immediately after deflateInit if all the compression 3050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is to be done in a single step. In this case, avail_out must be at least 3060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the value returned by deflateBound (see below). If deflate does not return 3070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_STREAM_END, then it must be called again as described above. 3080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate() sets strm->adler to the adler32 checksum of all input read 3100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath so far (that is, total_in bytes). 3110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate() may update strm->data_type if it can make a good guess about 3130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 3140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath binary. This field is only for information purposes and does not affect 3150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the compression algorithm in any manner. 3160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate() returns Z_OK if some progress has been made (more input 3180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath processed or more output produced), Z_STREAM_END if all input has been 3190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath consumed and all output has been produced (only when flush is set to 3200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 3210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible 3220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 3230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath fatal, and deflate() can be called again with more input and more output 3240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath space to continue compressing. 3250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 3260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 3290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 3300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath All dynamically allocated data structures for this stream are freed. 3310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function discards any unprocessed input and does not flush any 3320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath pending output. 3330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 3350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent, Z_DATA_ERROR if the stream was freed 3360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath prematurely (some input or output was discarded). In the error case, 3370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath msg may be set but then points to a static string (which must not be 3380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deallocated). 3390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 3400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 3430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 3440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Initializes the internal stream state for decompression. The fields 3460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath next_in, avail_in, zalloc, zfree and opaque must be initialized before by 3470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 3480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath value depends on the compression method), inflateInit determines the 3490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression method from the zlib header and allocates all data structures 3500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath accordingly; otherwise the allocation will be deferred to the first call of 3510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 3520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath use default allocation functions. 3530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 3550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 3560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath version assumed by the caller. msg is set to null if there is no error 3570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath message. inflateInit does not perform any decompression apart from reading 3580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the zlib header if present: this will be done by inflate(). (So next_in and 3590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath avail_in may be modified, but next_out and avail_out are unchanged.) 3600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 3610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 3640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 3650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate decompresses as much data as possible, and stops when the input 3660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath buffer becomes empty or the output buffer becomes full. It may introduce 3670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath some output latency (reading input without producing any output) except when 3680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath forced to flush. 3690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The detailed semantics are as follows. inflate performs one or both of the 3710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath following actions: 3720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath - Decompress more input starting at next_in and update next_in and avail_in 3740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath accordingly. If not all input can be processed (because there is not 3750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough room in the output buffer), next_in is updated and processing 3760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath will resume at this point for the next call of inflate(). 3770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath - Provide more output starting at next_out and update next_out and avail_out 3790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath accordingly. inflate() provides as much output as possible, until there 3800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is no more input data or no more space in the output buffer (see below 3810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath about the flush parameter). 3820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Before the call of inflate(), the application should ensure that at least 3840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath one of the actions is possible, by providing more input and/or consuming 3850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath more output, and updating the next_* and avail_* values accordingly. 3860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The application can consume the uncompressed output when it wants, for 3870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath example when the output buffer is full (avail_out == 0), or after each 3880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath call of inflate(). If inflate returns Z_OK and with zero avail_out, it 3890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath must be called again after making room in the output buffer because there 3900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath might be more output pending. 3910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, 3930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much 3940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath output as possible to the output buffer. Z_BLOCK requests that inflate() stop 3950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if and when it gets to the next deflate block boundary. When decoding the 3960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath zlib or gzip format, this will cause inflate() to return immediately after 3970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the header and before the first block. When doing a raw inflate, inflate() 3980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath will go ahead and process the first block, and will return when it gets to 3990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the end of that block, or when it runs out of data. 4000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The Z_BLOCK option assists in appending to or combining deflate streams. 4020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Also to assist in this, on return inflate() will set strm->data_type to the 4030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath number of unused bits in the last byte taken from strm->next_in, plus 64 4040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if inflate() is currently decoding the last block in the deflate stream, 4050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath plus 128 if inflate() returned immediately after decoding an end-of-block 4060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath code or decoding the complete header up to just before the first byte of the 4070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate stream. The end-of-block will not be indicated until all of the 4080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed data from that block has been written to strm->next_out. The 4090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath number of unused bits may in general be greater than seven, except when 4100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath bit 7 of data_type is set, in which case the number of unused bits will be 4110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath less than eight. 4120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate() should normally be called until it returns Z_STREAM_END or an 4140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath error. However if all decompression is to be performed in a single step 4150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (a single call of inflate), the parameter flush should be set to 4160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_FINISH. In this case all pending input is processed and all pending 4170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath output is flushed; avail_out must be large enough to hold all the 4180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed data. (The size of the uncompressed data may have been saved 4190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath by the compressor for this purpose.) The next operation on this stream must 4200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath be inflateEnd to deallocate the decompression state. The use of Z_FINISH 4210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is never required, but can be used to inform inflate that a faster approach 4220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath may be used for the single inflate() call. 4230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath In this implementation, inflate() always flushes as much output as 4250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath possible to the output buffer, and always uses the faster approach on the 4260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath first call. So the only effect of the flush parameter in this implementation 4270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is on the return value of inflate(), as noted below, or when it returns early 4280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath because Z_BLOCK is used. 4290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If a preset dictionary is needed after this call (see inflateSetDictionary 4310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath below), inflate sets strm->adler to the adler32 checksum of the dictionary 4320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 4330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath strm->adler to the adler32 checksum of all output produced so far (that is, 4340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 4350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath below. At the end of the stream, inflate() checks that its computed adler32 4360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath checksum is equal to that saved by the compressor and returns Z_STREAM_END 4370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath only if the checksum is correct. 4380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate() will decompress and check either zlib-wrapped or gzip-wrapped 4400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate data. The header type is detected automatically. Any information 4410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath contained in the gzip header is not retained, so applications that need that 4420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath information should instead use raw inflate, see inflateInit2() below, or 4430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBack() and perform their own processing of the gzip header and 4440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath trailer. 4450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate() returns Z_OK if some progress has been made (more input processed 4470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath or more output produced), Z_STREAM_END if the end of the compressed data has 4480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath been reached and all uncompressed output has been produced, Z_NEED_DICT if a 4490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 4500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath corrupted (input stream not conforming to the zlib format or incorrect check 4510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 4520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, 4530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_BUF_ERROR if no progress is possible or if there was not enough room in the 4540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 4550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate() can be called again with more input and more output space to 4560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath continue decompressing. If Z_DATA_ERROR is returned, the application may then 4570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath call inflateSync() to look for a good compression block if a partial recovery 4580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath of the data is desired. 4590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 4600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 4630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 4640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath All dynamically allocated data structures for this stream are freed. 4650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function discards any unprocessed input and does not flush any 4660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath pending output. 4670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 4690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath was inconsistent. In the error case, msg may be set but then points to a 4700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath static string (which must not be deallocated). 4710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 4720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath /* Advanced functions */ 4740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 4760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The following functions are needed only in some special applications. 4770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 4780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 4800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 4810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int level, 4820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int method, 4830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int windowBits, 4840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int memLevel, 4850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int strategy)); 4860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This is another version of deflateInit with more compression options. The 4880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath fields next_in, zalloc, zfree and opaque must be initialized before by 4890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the caller. 4900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The method parameter is the compression method. It must be Z_DEFLATED in 4920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath this version of the library. 4930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 4940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The windowBits parameter is the base two logarithm of the window size 4950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (the size of the history buffer). It should be in the range 8..15 for this 4960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath version of the library. Larger values of this parameter result in better 4970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression at the expense of memory usage. The default value is 15 if 4980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit is used instead. 4990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 5010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath determines the window size. deflate() will then generate raw deflate data 5020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath with no zlib header or trailer, and will not compute an adler32 check value. 5030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath windowBits can also be greater than 15 for optional gzip encoding. Add 5050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 16 to windowBits to write a simple gzip header and trailer around the 5060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressed data instead of a zlib wrapper. The gzip header will have no 5070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath file name, no extra data, no comment, no modification time (set to zero), 5080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath no header crc, and the operating system will be set to 255 (unknown). If a 5090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzip stream is being written, strm->adler is a crc32 instead of an adler32. 5100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The memLevel parameter specifies how much memory should be allocated 5120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath for the internal compression state. memLevel=1 uses minimum memory but 5130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is slow and reduces compression ratio; memLevel=9 uses maximum memory 5140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath for optimal speed. The default value is 8. See zconf.h for total memory 5150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath usage as a function of windowBits and memLevel. 5160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The strategy parameter is used to tune the compression algorithm. Use the 5180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 5190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 5200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath string match), or Z_RLE to limit match distances to one (run-length 5210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath encoding). Filtered data consists mostly of small values with a somewhat 5220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath random distribution. In this case, the compression algorithm is tuned to 5230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compress them better. The effect of Z_FILTERED is to force more Huffman 5240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath coding and less string matching; it is somewhat intermediate between 5250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as 5260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy 5270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath parameter only affects the compression ratio but not the correctness of the 5280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressed output even if it is not set appropriately. Z_FIXED prevents the 5290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath use of dynamic Huffman codes, allowing for a simpler decoder for special 5300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath applications. 5310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 5330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 5340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath method). msg is set to null if there is no error message. deflateInit2 does 5350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath not perform any compression: this will be done by deflate(). 5360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 5370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 5390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const Bytef *dictionary, 5400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt dictLength)); 5410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 5420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Initializes the compression dictionary from the given byte sequence 5430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath without producing any compressed output. This function must be called 5440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath immediately after deflateInit, deflateInit2 or deflateReset, before any 5450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath call of deflate. The compressor and decompressor must use exactly the same 5460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath dictionary (see inflateSetDictionary). 5470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The dictionary should consist of strings (byte sequences) that are likely 5490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath to be encountered later in the data to be compressed, with the most commonly 5500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath used strings preferably put towards the end of the dictionary. Using a 5510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath dictionary is most useful when the data to be compressed is short and can be 5520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath predicted with good accuracy; the data can then be compressed better than 5530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath with the default empty dictionary. 5540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Depending on the size of the compression data structures selected by 5560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit or deflateInit2, a part of the dictionary may in effect be 5570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath discarded, for example if the dictionary is larger than the window size in 5580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate or deflate2. Thus the strings most likely to be useful should be 5590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath put at the end of the dictionary, not at the front. In addition, the 5600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath current implementation of deflate will use at most the window size minus 5610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 262 bytes of the provided dictionary. 5620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Upon return of this function, strm->adler is set to the adler32 value 5640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath of the dictionary; the decompressor may later use this value to determine 5650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath which dictionary has been used by the compressor. (The adler32 value 5660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath applies to the whole dictionary even if only a subset of the dictionary is 5670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath actually used by the compressor.) If a raw deflate was requested, then the 5680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath adler32 value is not computed and strm->adler is not set. 5690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 5710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath parameter is invalid (such as NULL dictionary) or the stream state is 5720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inconsistent (for example if deflate has already been called for this stream 5730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath or if the compression method is bsort). deflateSetDictionary does not 5740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath perform any compression: this will be done by deflate(). 5750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 5760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 5780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath z_streamp source)); 5790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 5800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Sets the destination stream as a complete copy of the source stream. 5810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function can be useful when several compression strategies will be 5830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath tried, for example when there are several ways of pre-processing the input 5840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath data with a filter. The streams that will be discarded should then be freed 5850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath by calling deflateEnd. Note that deflateCopy duplicates the internal 5860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression state which can be quite large, so this strategy is slow and 5870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath can consume lots of memory. 5880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 5900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 5910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (such as zalloc being NULL). msg is left unchanged in both source and 5920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath destination. 5930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 5940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 5960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 5970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function is equivalent to deflateEnd followed by deflateInit, 5980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath but does not free and reallocate all the internal compression state. 5990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The stream will keep the same compression level and any other attributes 6000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath that may have been set by deflateInit2. 6010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 6030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent (such as zalloc or state being NULL). 6040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 6050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 6070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int level, 6080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int strategy)); 6090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 6100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Dynamically update the compression level and compression strategy. The 6110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath interpretation of level and strategy is as in deflateInit2. This can be 6120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath used to switch between compression and straight copy of the input data, or 6130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath to switch to a different kind of input data requiring a different 6140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath strategy. If the compression level is changed, the input available so far 6150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is compressed with the old level (and may be flushed); the new level will 6160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath take effect only at the next call of deflate(). 6170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Before the call of deflateParams, the stream state must be set as for 6190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath a call of deflate(), since the currently available input may have to 6200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath be compressed and flushed. In particular, strm->avail_out must be non-zero. 6210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 6230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 6240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if strm->avail_out was zero. 6250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 6260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 6280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int good_length, 6290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int max_lazy, 6300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int nice_length, 6310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int max_chain)); 6320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 6330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Fine tune deflate's internal compression parameters. This should only be 6340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath used by someone who understands the algorithm used by zlib's deflate for 6350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath searching for the best matching string, and even then only by the most 6360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath fanatic optimizer trying to squeeze out the last compressed bit for their 6370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath specific input data. Read the deflate.c source code for the meaning of the 6380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath max_lazy, good_length, nice_length, and max_chain parameters. 6390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateTune() can be called after deflateInit() or deflateInit2(), and 6410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 6420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath */ 6430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 6450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong sourceLen)); 6460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 6470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateBound() returns an upper bound on the compressed size after 6480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflation of sourceLen bytes. It must be called after deflateInit() 6490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath or deflateInit2(). This would be used to allocate an output buffer 6500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath for deflation in a single pass, and so would be called before deflate(). 6510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 6520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 6540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int bits, 6550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int value)); 6560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 6570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflatePrime() inserts bits in the deflate output stream. The intent 6580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is that this function is used to start off the deflate output with the 6590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath bits leftover from a previous deflate stream when appending to it. As such, 6600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath this function can only be used for raw deflate, and must be used before the 6610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath first deflate() call after a deflateInit2() or deflateReset(). bits must be 6620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath less than or equal to 16, and that many of the least significant bits of 6630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath value will be inserted in the output. 6640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 6660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent. 6670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 6680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 6700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gz_headerp head)); 6710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 6720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateSetHeader() provides gzip header information for when a gzip 6730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream is requested by deflateInit2(). deflateSetHeader() may be called 6740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath after deflateInit2() or deflateReset() and before the first call of 6750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate(). The text, time, os, extra field, name, and comment information 6760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath in the provided gz_header structure are written to the gzip header (xflag is 6770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath ignored -- the extra flags are set according to the compression level). The 6780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath caller must assure that, if not Z_NULL, name and comment are terminated with 6790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 6800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath available there. If hcrc is true, a gzip header crc is included. Note that 6810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the current versions of the command-line version of gzip (up through version 6820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1.3.x) do not support header crc's, and will report that it is a "multi-part 6830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzip file" and give up. 6840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If deflateSetHeader is not used, the default gzip header has text false, 6860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the time set to zero, and os set to 255, with no extra, name, or comment 6870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath fields. The gzip header is returned to the default state by deflateReset(). 6880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 6900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent. 6910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 6920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 6940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 6950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int windowBits)); 6960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 6970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This is another version of inflateInit with an extra parameter. The 6980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath fields next_in, avail_in, zalloc, zfree and opaque must be initialized 6990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath before by the caller. 7000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The windowBits parameter is the base two logarithm of the maximum window 7020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath size (the size of the history buffer). It should be in the range 8..15 for 7030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath this version of the library. The default value is 15 if inflateInit is used 7040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath instead. windowBits must be greater than or equal to the windowBits value 7050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath provided to deflateInit2() while compressing, or it must be equal to 15 if 7060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit2() was not used. If a compressed stream with a larger window 7070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath size is given as input, inflate() will return with the error code 7080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_DATA_ERROR instead of trying to allocate a larger window. 7090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 7110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath determines the window size. inflate() will then process raw deflate data, 7120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath not looking for a zlib or gzip header, not generating a check value, and not 7130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath looking for any check values for comparison at the end of the stream. This 7140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is for use with other formats that use the deflate compressed data format 7150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath such as zip. Those formats provide their own check values. If a custom 7160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath format is developed using the raw deflate format for compressed data, it is 7170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath recommended that a check value such as an adler32 or a crc32 be applied to 7180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the uncompressed data as is done in the zlib, gzip, and zip formats. For 7190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath most applications, the zlib format should be used as is. Note that comments 7200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath above on the use in deflateInit2() applies to the magnitude of windowBits. 7210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath windowBits can also be greater than 15 for optional gzip decoding. Add 7230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 32 to windowBits to enable zlib and gzip decoding with automatic header 7240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath detection, or add 16 to decode only the gzip format (the zlib format will 7250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 7260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath a crc32 instead of an adler32. 7270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 7290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg 7300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is set to null if there is no error message. inflateInit2 does not perform 7310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath any decompression apart from reading the zlib header if present: this will 7320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath be done by inflate(). (So next_in and avail_in may be modified, but next_out 7330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and avail_out are unchanged.) 7340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 7350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 7370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const Bytef *dictionary, 7380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uInt dictLength)); 7390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 7400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Initializes the decompression dictionary from the given uncompressed byte 7410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath sequence. This function must be called immediately after a call of inflate, 7420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 7430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath can be determined from the adler32 value returned by that call of inflate. 7440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The compressor and decompressor must use exactly the same dictionary (see 7450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateSetDictionary). For raw inflate, this function can be called 7460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath immediately after inflateInit2() or inflateReset() and before any call of 7470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate() to set the dictionary. The application must insure that the 7480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath dictionary that was used for compression is provided. 7490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 7510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath parameter is invalid (such as NULL dictionary) or the stream state is 7520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 7530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath expected one (incorrect adler32 value). inflateSetDictionary does not 7540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath perform any decompression: this will be done by subsequent calls of 7550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflate(). 7560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 7570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 7590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 7600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Skips invalid compressed data until a full flush point (see above the 7610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath description of deflate with Z_FULL_FLUSH) can be found, or until all 7620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath available input is skipped. No output is provided. 7630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 7650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if no more input was provided, Z_DATA_ERROR if no flush point has been found, 7660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 7670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath case, the application may save the current current value of total_in which 7680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath indicates where valid compressed data was found. In the error case, the 7690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath application may repeatedly call inflateSync, providing more input each time, 7700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath until success or end of the input data. 7710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 7720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 7740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath z_streamp source)); 7750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 7760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Sets the destination stream as a complete copy of the source stream. 7770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function can be useful when randomly accessing a large stream. The 7790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath first pass through the stream can periodically record the inflate state, 7800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath allowing restarting inflate at those points when randomly accessing the 7810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream. 7820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 7840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 7850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (such as zalloc being NULL). msg is left unchanged in both source and 7860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath destination. 7870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 7880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 7900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 7910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function is equivalent to inflateEnd followed by inflateInit, 7920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath but does not free and reallocate all the internal decompression state. 7930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The stream will keep attributes that may have been set by inflateInit2. 7940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 7960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent (such as zalloc or state being NULL). 7970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 7980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 8000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int bits, 8010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int value)); 8020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 8030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function inserts bits in the inflate input stream. The intent is 8040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath that this function is used to start inflating at a bit position in the 8050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath middle of a byte. The provided bits will be used before any bytes are used 8060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath from next_in. This function should only be used with raw inflate, and 8070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath should be used before the first inflate() call after inflateInit2() or 8080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateReset(). bits must be less than or equal to 16, and that many of the 8090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath least significant bits of value will be inserted in the input. 8100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 8120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent. 8130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 8140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 8160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gz_headerp head)); 8170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 8180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateGetHeader() requests that gzip header information be stored in the 8190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath provided gz_header structure. inflateGetHeader() may be called after 8200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateInit2() or inflateReset(), and before the first call of inflate(). 8210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath As inflate() processes the gzip stream, head->done is zero until the header 8220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is completed, at which time head->done is set to one. If a zlib stream is 8230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath being decoded, then head->done is set to -1 to indicate that there will be 8240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath no gzip header information forthcoming. Note that Z_BLOCK can be used to 8250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath force inflate() to return immediately after header processing is complete 8260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and before any actual data is decompressed. 8270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The text, time, xflags, and os fields are filled in with the gzip header 8290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath contents. hcrc is set to true if there is a header CRC. (The header CRC 8300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath was valid if done is set to one.) If extra is not Z_NULL, then extra_max 8310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath contains the maximum number of bytes to write to extra. Once done is true, 8320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath extra_len contains the actual extra field length, and extra contains the 8330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath extra field, or that field truncated if extra_max is less than extra_len. 8340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If name is not Z_NULL, then up to name_max characters are written there, 8350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath terminated with a zero unless the length is greater than name_max. If 8360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath comment is not Z_NULL, then up to comm_max characters are written there, 8370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath terminated with a zero unless the length is greater than comm_max. When 8380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath any of extra, name, or comment are not Z_NULL and the respective field is 8390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath not present in the header, then that field is set to Z_NULL to signal its 8400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath absence. This allows the use of deflateSetHeader() with the returned 8410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath structure to duplicate the header. However if those fields are set to 8420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath allocated memory, then the application will need to save those pointers 8430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath elsewhere so that they can be eventually freed. 8440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If inflateGetHeader is not used, then the header information is simply 8460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath discarded. The header is always checked for validity, including the header 8470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath CRC if present. inflateReset() will reset the process to discard the header 8480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath information. The application would need to call inflateGetHeader() again to 8490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath retrieve the header from the next gzip stream. 8500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 8520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath stream state was inconsistent. 8530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 8540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 8560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 8570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath unsigned char FAR *window)); 8580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Initialize the internal stream state for decompression using inflateBack() 8600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath calls. The fields zalloc, zfree and opaque in strm must be initialized 8610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath before the call. If zalloc and zfree are Z_NULL, then the default library- 8620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath derived memory allocation routines are used. windowBits is the base two 8630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath logarithm of the window size, in the range 8..15. window is a caller 8640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath supplied buffer of that size. Except for special applications where it is 8650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath assured that deflate was used with small window sizes, windowBits must be 15 8660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and a 32K byte window must be supplied to be able to decompress general 8670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate streams. 8680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath See inflateBack() for the usage of these routines. 8700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 8720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the paramaters are invalid, Z_MEM_ERROR if the internal state could not 8730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath be allocated, or Z_VERSION_ERROR if the version of the library does not 8740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath match the version of the header file. 8750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 8760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 8780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 8790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 8810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath in_func in, void FAR *in_desc, 8820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath out_func out, void FAR *out_desc)); 8830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 8840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBack() does a raw inflate with a single call using a call-back 8850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath interface for input and output. This is more efficient than inflate() for 8860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath file i/o applications in that it avoids copying between the output and the 8870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath sliding window by simply making the window itself the output buffer. This 8880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath function trusts the application to not change the output buffer passed by 8890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the output function, at least until inflateBack() returns. 8900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBackInit() must be called first to allocate the internal state 8920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and to initialize the state with the user-provided window buffer. 8930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBack() may then be used multiple times to inflate a complete, raw 8940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate stream with each call. inflateBackEnd() is then called to free 8950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the allocated state. 8960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath A raw deflate stream is one with no zlib or gzip header or trailer. 8980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This routine would normally be used in a utility that reads zip or gzip 8990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath files and writes out uncompressed files. The utility would decode the 9000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath header and process the trailer on its own, hence this routine expects 9010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath only the raw deflate stream to decompress. This is different from the 9020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath normal behavior of inflate(), which expects either a zlib or gzip header and 9030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath trailer around the deflate stream. 9040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBack() uses two subroutines supplied by the caller that are then 9060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath called by inflateBack() for input and output. inflateBack() calls those 9070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath routines until it reads a complete deflate stream and writes out all of the 9080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed data, or until it encounters an error. The function's 9090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath parameters and return types are defined above in the in_func and out_func 9100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath typedefs. inflateBack() will call in(in_desc, &buf) which should return the 9110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath number of bytes of provided input, and a pointer to that input in buf. If 9120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath there is no input available, in() must return zero--buf is ignored in that 9130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath case--and inflateBack() will return a buffer error. inflateBack() will call 9140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 9150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath should return zero on success, or non-zero on failure. If out() returns 9160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath non-zero, inflateBack() will return with an error. Neither in() nor out() 9170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath are permitted to change the contents of the window provided to 9180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBackInit(), which is also the buffer that out() uses to write from. 9190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The length written by out() will be at most the window size. Any non-zero 9200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath amount of input may be provided by in(). 9210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath For convenience, inflateBack() can be provided input on the first call by 9230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath setting strm->next_in and strm->avail_in. If that input is exhausted, then 9240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath in() will be called. Therefore strm->next_in must be initialized before 9250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 9260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 9270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath must also be initialized, and then if strm->avail_in is not zero, input will 9280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 9290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The in_desc and out_desc parameters of inflateBack() is passed as the 9310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath first parameter of in() and out() respectively when they are called. These 9320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath descriptors can be optionally used to pass any information that the caller- 9330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath supplied in() and out() functions need to do their job. 9340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath On return, inflateBack() will set strm->next_in and strm->avail_in to 9360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath pass back any unused input that was provided by the last in() call. The 9370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 9380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if in() or out() returned an error, Z_DATA_ERROR if there was a format 9390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath error in the deflate stream (in which case strm->msg is set to indicate the 9400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath nature of the error), or Z_STREAM_ERROR if the stream was not properly 9410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath initialized. In the case of Z_BUF_ERROR, an input or output error can be 9420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath distinguished using strm->next_in which will be Z_NULL only if in() returned 9430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to 9440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath out() returning non-zero. (in() will always be called before out(), so 9450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath strm->next_in is assured to be defined if out() returns non-zero.) Note 9460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath that inflateBack() cannot return Z_OK. 9470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 9480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 9500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 9510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath All memory allocated by inflateBackInit() is freed. 9520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 9540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath state was inconsistent. 9550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 9560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 9580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* Return flags indicating compile-time options. 9590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 9610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 1.0: size of uInt 9620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 3.2: size of uLong 9630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 5.4: size of voidpf (pointer) 9640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 7.6: size of z_off_t 9650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Compiler, assembler, and debug options: 9670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 8: DEBUG 9680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9: ASMV or ASMINF -- use ASM code 9690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 9700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11: 0 (reserved) 9710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath One-time table building (smaller code, but not thread-safe if true): 9730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12: BUILDFIXED -- build static block decoding tables when needed 9740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 9750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 14,15: 0 (reserved) 9760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Library content (indicates missing functionality): 9780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 9790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflate code when not needed) 9800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 9810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and decode gzip streams (to avoid linking crc code) 9820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 18-19: 0 (reserved) 9830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Operation variations (changes in library functionality): 9850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 9860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 21: FASTEST -- deflate algorithm with only one, lowest compression level 9870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 22,23: 0 (reserved) 9880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The sprintf variant used by gzprintf (zero is best): 9900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 9910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 9920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 9930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Remainder: 9950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 27-31: 0 (reserved) 9960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath */ 9970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 9990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath /* utility functions */ 10000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The following utility functions are implemented on top of the 10030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath basic stream-oriented functions. To simplify the interface, some 10040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath default options are assumed (compression level and memory usage, 10050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath standard memory allocation functions). The source code of these 10060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath utility functions can easily be modified if you need special options. 10070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 10080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 10100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const Bytef *source, uLong sourceLen)); 10110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Compresses the source buffer into the destination buffer. sourceLen is 10130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the byte length of the source buffer. Upon entry, destLen is the total 10140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath size of the destination buffer, which must be at least the value returned 10150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath by compressBound(sourceLen). Upon exit, destLen is the actual size of the 10160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressed buffer. 10170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function can be used to compress a whole file at once if the 10180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath input file is mmap'ed. 10190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compress returns Z_OK if success, Z_MEM_ERROR if there was not 10200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough memory, Z_BUF_ERROR if there was not enough room in the output 10210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath buffer. 10220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 10230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 10250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const Bytef *source, uLong sourceLen, 10260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int level)); 10270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Compresses the source buffer into the destination buffer. The level 10290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath parameter has the same meaning as in deflateInit. sourceLen is the byte 10300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath length of the source buffer. Upon entry, destLen is the total size of the 10310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath destination buffer, which must be at least the value returned by 10320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressBound(sourceLen). Upon exit, destLen is the actual size of the 10330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressed buffer. 10340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 10360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath memory, Z_BUF_ERROR if there was not enough room in the output buffer, 10370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Z_STREAM_ERROR if the level parameter is invalid. 10380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 10390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 10410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compressBound() returns an upper bound on the compressed size after 10430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compress() or compress2() on sourceLen bytes. It would be used before 10440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath a compress() or compress2() call to allocate the destination buffer. 10450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 10460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 10480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const Bytef *source, uLong sourceLen)); 10490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Decompresses the source buffer into the destination buffer. sourceLen is 10510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the byte length of the source buffer. Upon entry, destLen is the total 10520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath size of the destination buffer, which must be large enough to hold the 10530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath entire uncompressed data. (The size of the uncompressed data must have 10540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath been saved previously by the compressor and transmitted to the decompressor 10550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath by some mechanism outside the scope of this compression library.) 10560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Upon exit, destLen is the actual size of the compressed buffer. 10570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function can be used to decompress a whole file at once if the 10580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath input file is mmap'ed. 10590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 10610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath enough memory, Z_BUF_ERROR if there was not enough room in the output 10620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. 10630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 10640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathtypedef voidp gzFile; 10670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 10690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Opens a gzip (.gz) file for reading or writing. The mode parameter 10710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath is as in fopen ("rb" or "wb") but can also include a compression level 10720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 10730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Huffman only compression as in "wb1h", or 'R' for run-length encoding 10740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath as in "wb1R". (See the description of deflateInit2 for more information 10750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath about the strategy parameter.) 10760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzopen can be used to read a file which is not in gzip format; in this 10780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath case gzread will directly read from the file without decompression. 10790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzopen returns NULL if the file could not be opened or if there was 10810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath insufficient memory to allocate the (de)compression state; errno 10820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath can be checked to distinguish the two cases (if errno is zero, the 10830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath zlib error is Z_MEM_ERROR). */ 10840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamathlong long gzgetMtime(gzFile file); 10860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* Return modify time */ 10870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 10880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 10890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 10900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzdopen() associates a gzFile with the file descriptor fd. File 10910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath descriptors are obtained from calls like open, dup, creat, pipe or 10920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath fileno (in the file has been previously opened with fopen). 10930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The mode parameter is as in gzopen. 10940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath The next call of gzclose on the returned gzFile will also close the 10950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 10960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 10970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzdopen returns NULL if there was insufficient memory to allocate 10980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the (de)compression state. 10990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 11020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Dynamically update the compression level or strategy. See the description 11040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath of deflateInit2 for the meaning of these parameters. 11050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 11060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath opened for writing. 11070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 11100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Reads the given number of uncompressed bytes from the compressed file. 11120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If the input file was not in gzip format, gzread copies the given number 11130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath of bytes into the buffer. 11140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzread returns the number of uncompressed bytes actually read (0 for 11150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath end of file, -1 for error). */ 11160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzwrite OF((gzFile file, 11180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath voidpc buf, unsigned len)); 11190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Writes the given number of uncompressed bytes into the compressed file. 11210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzwrite returns the number of uncompressed bytes actually written 11220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (0 in case of error). 11230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 11260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Converts, formats, and writes the args to the compressed file under 11280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath control of the format string, as in fprintf. gzprintf returns the number of 11290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed bytes actually written (0 in case of error). The number of 11300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed bytes written is limited to 4095. The caller should assure that 11310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath this limit is not exceeded. If it is exceeded, then gzprintf() will return 11320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath return an error (0) with nothing written. In this case, there may also be a 11330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath buffer overflow with unpredictable consequences, which is possible only if 11340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath zlib was compiled with the insecure functions sprintf() or vsprintf() 11350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath because the secure snprintf() or vsnprintf() functions were not available. 11360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 11390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Writes the given null-terminated string to the compressed file, excluding 11410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the terminating null character. 11420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzputs returns the number of characters written, or -1 in case of error. 11430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 11460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Reads bytes from the compressed file until len-1 characters are read, or 11480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath a newline character is read and transferred to buf, or an end-of-file 11490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath condition is encountered. The string is then terminated with a null 11500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath character. 11510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzgets returns buf, or Z_NULL in case of error. 11520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 11550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Writes c, converted to an unsigned char, into the compressed file. 11570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzputc returns the value that was written, or -1 in case of error. 11580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 11610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Reads one byte from the compressed file. gzgetc returns this byte 11630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath or -1 in case of end of file or error. 11640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 11670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Push one character back onto the stream to be read again later. 11690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Only one character of push-back is allowed. gzungetc() returns the 11700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath character pushed, or -1 on failure. gzungetc() will fail if a 11710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath character has been pushed but not read yet, or if c is -1. The pushed 11720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath character will be discarded if the stream is repositioned with gzseek() 11730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath or gzrewind(). 11740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 11770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Flushes all pending output into the compressed file. The parameter 11790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath flush is as in the deflate() function. The return value is the zlib 11800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath error number (see function gzerror below). gzflush returns Z_OK if 11810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the flush parameter is Z_FINISH and all output could be flushed. 11820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzflush should be called only when strictly necessary because it can 11830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath degrade compression. 11840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 11850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 11870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath z_off_t offset, int whence)); 11880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 11890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Sets the starting position for the next gzread or gzwrite on the 11900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath given compressed file. The offset represents a number of bytes in the 11910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed data stream. The whence parameter is defined as in lseek(2); 11920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the value SEEK_END is not supported. 11930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath If the file is opened for reading, this function is emulated but can be 11940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath extremely slow. If the file is opened for writing, only forward seeks are 11950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath supported; gzseek then compresses a sequence of zeroes up to the new 11960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath starting position. 11970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 11980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzseek returns the resulting offset location as measured in bytes from 11990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the beginning of the uncompressed stream, or -1 in case of error, in 12000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath particular if the file is opened for writing and the new starting position 12010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath would be before the current position. 12020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 12050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Rewinds the given file. This function is supported only for reading. 12070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 12090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 12120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Returns the starting position for the next gzread or gzwrite on the 12140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath given compressed file. This position represents a number of bytes in the 12150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uncompressed data stream. 12160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 12180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzeof OF((gzFile file)); 12210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Returns 1 when EOF has previously been detected reading the given 12230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath input stream, otherwise zero. 12240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 12270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Returns 1 if file is being read directly without decompression, otherwise 12290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath zero. 12300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT gzclose OF((gzFile file)); 12330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Flushes all pending output if necessary, closes the compressed file 12350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and deallocates all the (de)compression state. The return value is the zlib 12360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath error number (see function gzerror below). 12370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 12400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Returns the error message for the last error which occurred on the 12420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath given compressed file. errnum is set to zlib error number. If an 12430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath error occurred in the file system and not in the compression library, 12440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath errnum is set to Z_ERRNO and the application may consult errno 12450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath to get the exact error code. 12460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 12490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Clears the error and end-of-file flags for file. This is analogous to the 12510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath clearerr() function in stdio. This is useful for continuing to read a gzip 12520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath file that is being written concurrently. 12530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath /* checksum functions */ 12560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath These functions are not related to compression but are exported 12590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath anyway because they might be useful in applications using the 12600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath compression library. 12610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 12640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Update a running Adler-32 checksum with the bytes buf[0..len-1] and 12660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath return the updated checksum. If buf is NULL, this function returns 12670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath the required initial value for the checksum. 12680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 12690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath much faster. Usage example: 12700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong adler = adler32(0L, Z_NULL, 0); 12720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath while (read_buffer(buffer, length) != EOF) { 12740a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath adler = adler32(adler, buffer, length); 12750a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath } 12760a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if (adler != original_adler) error(); 12770a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12780a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12790a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN void ZEXPORT adler32_range OF((uLong* min, uLong* max)); 12800a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12810a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Set *min and *max (both of which must not be null) to the minimum and 12820a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath maximum possible checksum values that adler32 can produce. 12830a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12840a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath This function is not part of original software distribution. It is 12850a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath added at Google (2003) in accordance with the copyright notice above, 12860a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath which permits alteration and redistribution of the original software 12870a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath provided, among other things, that altered source versions must be 12880a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath plainly marked as such and not misrepresented as being the original 12890a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath software. 12900a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 12910a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 12920a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 12930a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath z_off_t len2)); 12940a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 12950a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 12960a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 12970a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 12980a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. 12990a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 13000a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13010a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 13020a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 13030a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Update a running CRC-32 with the bytes buf[0..len-1] and return the 13040a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath updated CRC-32. If buf is NULL, this function returns the required initial 13050a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath value for the for the crc. Pre- and post-conditioning (one's complement) is 13060a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath performed within this function so it shouldn't be done by the application. 13070a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Usage example: 13080a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13090a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath uLong crc = crc32(0L, Z_NULL, 0); 13100a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13110a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath while (read_buffer(buffer, length) != EOF) { 13120a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath crc = crc32(crc, buffer, length); 13130a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath } 13140a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath if (crc != original_crc) error(); 13150a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 13160a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13170a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 13180a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13190a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* 13200a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath Combine two CRC-32 check values into one. For two sequences of bytes, 13210a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 13220a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 13230a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 13240a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath len2. 13250a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath*/ 13260a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13270a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13280a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath /* various hacks, don't look :) */ 13290a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13300a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath/* deflateInit and inflateInit are macros to allow checking the zlib version 13310a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath * and the compiler's view of z_stream: 13320a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath */ 13330a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 13340a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const char *version, int stream_size)); 13350a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 13360a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const char *version, int stream_size)); 13370a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 13380a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int windowBits, int memLevel, 13390a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int strategy, const char *version, 13400a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int stream_size)); 13410a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 13420a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const char *version, int stream_size)); 13430a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 13440a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath unsigned char FAR *window, 13450a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath const char *version, 13460a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath int stream_size)); 13470a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define deflateInit(strm, level) \ 13480a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) 13490a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define inflateInit(strm) \ 13500a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) 13510a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 13520a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 13530a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath (strategy), ZLIB_VERSION, sizeof(z_stream)) 13540a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define inflateInit2(strm, windowBits) \ 13550a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 13560a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#define inflateBackInit(strm, windowBits, window) \ 13570a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath inflateBackInit_((strm), (windowBits), (window), \ 13580a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath ZLIB_VERSION, sizeof(z_stream)) 13590a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13600a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13610a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) 13620a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath struct internal_state {int dummy;}; /* hack for buggy compilers */ 13630a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#endif 13640a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13650a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN const char * ZEXPORT zError OF((int)); 13660a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); 13670a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan KamathZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); 13680a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13690a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#ifdef __cplusplus 13700a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath} 13710a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#endif 13720a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath 13730a58c5c2f73e5047b36f12b5f12b12d6f2a9f69dNarayan Kamath#endif /* ZLIB_H */ 1374