williamr@2: /* zlib.h -- interface of the 'zlib' general purpose compression library williamr@2: version 1.1.3, July 9th, 1998 williamr@2: williamr@2: Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler williamr@2: williamr@2: This software is provided 'as-is', without any express or implied williamr@2: warranty. In no event will the authors be held liable for any damages williamr@2: arising from the use of this software. williamr@2: williamr@2: Permission is granted to anyone to use this software for any purpose, williamr@2: including commercial applications, and to alter it and redistribute it williamr@2: freely, subject to the following restrictions: williamr@2: williamr@2: 1. The origin of this software must not be misrepresented; you must not williamr@2: claim that you wrote the original software. If you use this software williamr@2: in a product, an acknowledgment in the product documentation would be williamr@2: appreciated but is not required. williamr@2: 2. Altered source versions must be plainly marked as such, and must not be williamr@2: misrepresented as being the original software. williamr@2: 3. This notice may not be removed or altered from any source distribution. williamr@2: williamr@2: Jean-loup Gailly Mark Adler williamr@2: jloup@gzip.org madler@alumni.caltech.edu williamr@2: williamr@2: williamr@2: The data format used by the zlib library is described by RFCs (Request for williamr@2: Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt williamr@2: (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). williamr@2: */ williamr@2: williamr@2: /* williamr@2: This is an altered version of the zlib library designed to run on EPOC williamr@2: Symbian Markr 5/11/99 williamr@2: */ williamr@2: williamr@2: #ifndef _ZLIB_H williamr@2: #define _ZLIB_H williamr@2: williamr@2: #ifdef __cplusplus williamr@2: extern "C" { williamr@2: #endif williamr@2: williamr@2: #include williamr@2: williamr@2: #define ZLIB_VERSION "1.1.3" williamr@2: williamr@2: /* williamr@2: The 'zlib' compression library provides in-memory compression and williamr@2: decompression functions, including integrity checks of the uncompressed williamr@2: data. This version of the library supports only one compression method williamr@2: (deflation) but other algorithms will be added later and will have the same williamr@2: stream interface. williamr@2: williamr@2: Compression can be done in a single step if the buffers are large williamr@2: enough (for example if an input file is mmap'ed), or can be done by williamr@2: repeated calls of the compression function. In the latter case, the williamr@2: application must provide more input and/or consume the output williamr@2: (providing more output space) before each call. williamr@2: williamr@2: The library also supports reading and writing files in gzip (.gz) format williamr@2: with an interface similar to that of stdio. williamr@2: williamr@2: The library does not install any signal handler. The decoder checks williamr@2: the consistency of the compressed data, so the library should never williamr@2: crash even in case of corrupted input. williamr@2: */ williamr@2: williamr@2: typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); williamr@2: typedef void (*free_func) OF((voidpf opaque, voidpf address)); williamr@2: williamr@2: struct internal_state; williamr@2: williamr@2: /** williamr@2: Encapsulates a zip stream williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef struct z_stream_s { williamr@2: /** next input byte */ williamr@2: Bytef *next_in; williamr@2: /** number of bytes available at next_in */ williamr@2: uInt avail_in; williamr@2: /** total nb of input bytes read so far */ williamr@2: uLong total_in; williamr@2: williamr@2: /** next output byte should be put there */ williamr@2: Bytef *next_out; williamr@2: /** remaining free space at next_out */ williamr@2: uInt avail_out; williamr@2: /** total nb of bytes output so far */ williamr@2: uLong total_out; williamr@2: williamr@2: /** last error message, NULL if no error */ williamr@2: char *msg; williamr@2: /* not visible by applications */ williamr@2: struct internal_state FAR *state; williamr@2: williamr@2: /** used to allocate the internal state */ williamr@2: alloc_func zalloc; williamr@2: /** used to free the internal state */ williamr@2: free_func zfree; williamr@2: /** private data object passed to zalloc and zfree */ williamr@2: voidpf opaque; williamr@2: williamr@2: /** best guess about the data type: ascii or binary */ williamr@2: int data_type; williamr@2: /** adler32 value of the uncompressed data */ williamr@2: uLong adler; williamr@2: /** reserved for future use */ williamr@2: uLong reserved; williamr@2: } z_stream; williamr@2: williamr@2: typedef z_stream FAR *z_streamp; williamr@2: williamr@2: /* williamr@2: The application must update next_in and avail_in when avail_in has williamr@2: dropped to zero. It must update next_out and avail_out when avail_out williamr@2: has dropped to zero. The application must initialize zalloc, zfree and williamr@2: opaque before calling the init function. All other fields are set by the williamr@2: compression library and must not be updated by the application. williamr@2: williamr@2: The opaque value provided by the application will be passed as the first williamr@2: parameter for calls of zalloc and zfree. This can be useful for custom williamr@2: memory management. The compression library attaches no meaning to the williamr@2: opaque value. williamr@2: williamr@2: zalloc must return Z_NULL if there is not enough memory for the object. williamr@2: If zlib is used in a multi-threaded application, zalloc and zfree must be williamr@2: thread safe. williamr@2: williamr@2: On 16-bit systems, the functions zalloc and zfree must be able to allocate williamr@2: exactly 65536 bytes, but will not be required to allocate more than this williamr@2: if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, williamr@2: pointers returned by zalloc for objects of exactly 65536 bytes *must* williamr@2: have their offset normalized to zero. The default allocation function williamr@2: provided by this library ensures this (see zutil.c). To reduce memory williamr@2: requirements and avoid any allocation of 64K objects, at the expense of williamr@2: compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). williamr@2: williamr@2: The fields total_in and total_out can be used for statistics or williamr@2: progress reports. After compression, total_in holds the total size of williamr@2: the uncompressed data and may be saved for use in the decompressor williamr@2: (particularly if the decompressor wants to decompress everything in williamr@2: a single step). williamr@2: */ williamr@2: williamr@2: /* constants */ williamr@2: williamr@2: #define Z_NO_FLUSH 0 williamr@2: #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ williamr@2: #define Z_SYNC_FLUSH 2 williamr@2: #define Z_FULL_FLUSH 3 williamr@2: #define Z_FINISH 4 williamr@2: /* Allowed flush values; see deflate() below for details */ williamr@2: williamr@2: #define Z_OK 0 williamr@2: #define Z_STREAM_END 1 williamr@2: #define Z_NEED_DICT 2 williamr@2: #define Z_ERRNO (-1) williamr@2: #define Z_STREAM_ERROR (-2) williamr@2: #define Z_DATA_ERROR (-3) williamr@2: #define Z_MEM_ERROR (-4) williamr@2: #define Z_BUF_ERROR (-5) williamr@2: #define Z_VERSION_ERROR (-6) williamr@2: /* Return codes for the compression/decompression functions. Negative williamr@2: * values are errors, positive values are used for special but normal events. williamr@2: */ williamr@2: williamr@2: #define Z_NO_COMPRESSION 0 williamr@2: #define Z_BEST_SPEED 1 williamr@2: #define Z_BEST_COMPRESSION 9 williamr@2: #define Z_DEFAULT_COMPRESSION (-1) williamr@2: /* compression levels */ williamr@2: williamr@2: #define Z_FILTERED 1 williamr@2: #define Z_HUFFMAN_ONLY 2 williamr@2: #define Z_DEFAULT_STRATEGY 0 williamr@2: /* compression strategy; see deflateInit2() below for details */ williamr@2: williamr@2: #define Z_BINARY 0 williamr@2: #define Z_ASCII 1 williamr@2: #define Z_UNKNOWN 2 williamr@2: /* Possible values of the data_type field */ williamr@2: williamr@2: #define Z_DEFLATED 8 williamr@2: /* The deflate compression method (the only one supported in this version) */ williamr@2: williamr@2: #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ williamr@2: williamr@2: #define zlib_version zlibVersion() williamr@2: /* for compatibility with versions < 1.0.2 */ williamr@2: williamr@2: /* basic functions */ williamr@2: williamr@2: ZEXTERN const char * ZEXPORT zlibVersion OF((void)); williamr@2: /* The application can compare zlibVersion and ZLIB_VERSION for consistency. williamr@2: If the first character differs, the library code actually used is williamr@2: not compatible with the zlib.h header file used by the application. williamr@2: This check is automatically made by deflateInit and inflateInit. williamr@2: */ williamr@2: williamr@2: /* williamr@2: ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); williamr@2: williamr@2: Initializes the internal stream state for compression. The fields williamr@2: zalloc, zfree and opaque must be initialized before by the caller. williamr@2: If zalloc and zfree are set to Z_NULL, deflateInit updates them to williamr@2: use default allocation functions. williamr@2: williamr@2: The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: williamr@2: 1 gives best speed, 9 gives best compression, 0 gives no compression at williamr@2: all (the input data is simply copied a block at a time). williamr@2: Z_DEFAULT_COMPRESSION requests a default compromise between speed and williamr@2: compression (currently equivalent to level 6). williamr@2: williamr@2: deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not williamr@2: enough memory, Z_STREAM_ERROR if level is not a valid compression level, williamr@2: Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible williamr@2: with the version assumed by the caller (ZLIB_VERSION). williamr@2: msg is set to null if there is no error message. deflateInit does not williamr@2: perform any compression: this will be done by deflate(). williamr@2: */ williamr@2: williamr@2: williamr@2: ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); williamr@2: /* williamr@2: deflate compresses as much data as possible, and stops when the input williamr@2: buffer becomes empty or the output buffer becomes full. It may introduce some williamr@2: output latency (reading input without producing any output) except when williamr@2: forced to flush. williamr@2: williamr@2: The detailed semantics are as follows. deflate performs one or both of the williamr@2: following actions: williamr@2: williamr@2: - Compress more input starting at next_in and update next_in and avail_in williamr@2: accordingly. If not all input can be processed (because there is not williamr@2: enough room in the output buffer), next_in and avail_in are updated and williamr@2: processing will resume at this point for the next call of deflate(). williamr@2: williamr@2: - Provide more output starting at next_out and update next_out and avail_out williamr@2: accordingly. This action is forced if the parameter flush is non zero. williamr@2: Forcing flush frequently degrades the compression ratio, so this parameter williamr@2: should be set only when necessary (in interactive applications). williamr@2: Some output may be provided even if flush is not set. williamr@2: williamr@2: Before the call of deflate(), the application should ensure that at least williamr@2: one of the actions is possible, by providing more input and/or consuming williamr@2: more output, and updating avail_in or avail_out accordingly; avail_out williamr@2: should never be zero before the call. The application can consume the williamr@2: compressed output when it wants, for example when the output buffer is full williamr@2: (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK williamr@2: and with zero avail_out, it must be called again after making room in the williamr@2: output buffer because there might be more output pending. williamr@2: williamr@2: If the parameter flush is set to Z_SYNC_FLUSH, all pending output is williamr@2: flushed to the output buffer and the output is aligned on a byte boundary, so williamr@2: that the decompressor can get all input data available so far. (In particular williamr@2: avail_in is zero after the call if enough output space has been provided williamr@2: before the call.) Flushing may degrade compression for some compression williamr@2: algorithms and so it should be used only when necessary. williamr@2: williamr@2: If flush is set to Z_FULL_FLUSH, all output is flushed as with williamr@2: Z_SYNC_FLUSH, and the compression state is reset so that decompression can williamr@2: restart from this point if previous compressed data has been damaged or if williamr@2: random access is desired. Using Z_FULL_FLUSH too often can seriously degrade williamr@2: the compression. williamr@2: williamr@2: If deflate returns with avail_out == 0, this function must be called again williamr@2: with the same value of the flush parameter and more output space (updated williamr@2: avail_out), until the flush is complete (deflate returns with non-zero williamr@2: avail_out). williamr@2: williamr@2: If the parameter flush is set to Z_FINISH, pending input is processed, williamr@2: pending output is flushed and deflate returns with Z_STREAM_END if there williamr@2: was enough output space; if deflate returns with Z_OK, this function must be williamr@2: called again with Z_FINISH and more output space (updated avail_out) but no williamr@2: more input data, until it returns with Z_STREAM_END or an error. After williamr@2: deflate has returned Z_STREAM_END, the only possible operations on the williamr@2: stream are deflateReset or deflateEnd. williamr@2: williamr@2: Z_FINISH can be used immediately after deflateInit if all the compression williamr@2: is to be done in a single step. In this case, avail_out must be at least williamr@2: 0.1% larger than avail_in plus 12 bytes. If deflate does not return williamr@2: Z_STREAM_END, then it must be called again as described above. williamr@2: williamr@2: deflate() sets strm->adler to the adler32 checksum of all input read williamr@2: so far (that is, total_in bytes). williamr@2: williamr@2: deflate() may update data_type if it can make a good guess about williamr@2: the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered williamr@2: binary. This field is only for information purposes and does not affect williamr@2: the compression algorithm in any manner. williamr@2: williamr@2: deflate() returns Z_OK if some progress has been made (more input williamr@2: processed or more output produced), Z_STREAM_END if all input has been williamr@2: consumed and all output has been produced (only when flush is set to williamr@2: Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example williamr@2: if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible williamr@2: (for example avail_in or avail_out was zero). williamr@2: */ williamr@2: williamr@2: williamr@2: ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); williamr@2: /* williamr@2: All dynamically allocated data structures for this stream are freed. williamr@2: This function discards any unprocessed input and does not flush any williamr@2: pending output. williamr@2: williamr@2: deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the williamr@2: stream state was inconsistent, Z_DATA_ERROR if the stream was freed williamr@2: prematurely (some input or output was discarded). In the error case, williamr@2: msg may be set but then points to a static string (which must not be williamr@2: deallocated). williamr@2: */ williamr@2: williamr@2: williamr@2: /* williamr@2: ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); williamr@2: williamr@2: Initializes the internal stream state for decompression. The fields williamr@2: next_in, avail_in, zalloc, zfree and opaque must be initialized before by williamr@2: the caller. If next_in is not Z_NULL and avail_in is large enough (the exact williamr@2: value depends on the compression method), inflateInit determines the williamr@2: compression method from the zlib header and allocates all data structures williamr@2: accordingly; otherwise the allocation will be deferred to the first call of williamr@2: inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to williamr@2: use default allocation functions. williamr@2: williamr@2: inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough williamr@2: memory, Z_VERSION_ERROR if the zlib library version is incompatible with the williamr@2: version assumed by the caller. msg is set to null if there is no error williamr@2: message. inflateInit does not perform any decompression apart from reading williamr@2: the zlib header if present: this will be done by inflate(). (So next_in and williamr@2: avail_in may be modified, but next_out and avail_out are unchanged.) williamr@2: */ williamr@2: williamr@2: williamr@2: ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); williamr@2: /* williamr@2: inflate decompresses as much data as possible, and stops when the input williamr@2: buffer becomes empty or the output buffer becomes full. It may some williamr@2: introduce some output latency (reading input without producing any output) williamr@2: except when forced to flush. williamr@2: williamr@2: The detailed semantics are as follows. inflate performs one or both of the williamr@2: following actions: williamr@2: williamr@2: - Decompress more input starting at next_in and update next_in and avail_in williamr@2: accordingly. If not all input can be processed (because there is not williamr@2: enough room in the output buffer), next_in is updated and processing williamr@2: will resume at this point for the next call of inflate(). williamr@2: williamr@2: - Provide more output starting at next_out and update next_out and avail_out williamr@2: accordingly. inflate() provides as much output as possible, until there williamr@2: is no more input data or no more space in the output buffer (see below williamr@2: about the flush parameter). williamr@2: williamr@2: Before the call of inflate(), the application should ensure that at least williamr@2: one of the actions is possible, by providing more input and/or consuming williamr@2: more output, and updating the next_* and avail_* values accordingly. williamr@2: The application can consume the uncompressed output when it wants, for williamr@2: example when the output buffer is full (avail_out == 0), or after each williamr@2: call of inflate(). If inflate returns Z_OK and with zero avail_out, it williamr@2: must be called again after making room in the output buffer because there williamr@2: might be more output pending. williamr@2: williamr@2: If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much williamr@2: output as possible to the output buffer. The flushing behavior of inflate is williamr@2: not specified for values of the flush parameter other than Z_SYNC_FLUSH williamr@2: and Z_FINISH, but the current implementation actually flushes as much output williamr@2: as possible anyway. williamr@2: williamr@2: inflate() should normally be called until it returns Z_STREAM_END or an williamr@2: error. However if all decompression is to be performed in a single step williamr@2: (a single call of inflate), the parameter flush should be set to williamr@2: Z_FINISH. In this case all pending input is processed and all pending williamr@2: output is flushed; avail_out must be large enough to hold all the williamr@2: uncompressed data. (The size of the uncompressed data may have been saved williamr@2: by the compressor for this purpose.) The next operation on this stream must williamr@2: be inflateEnd to deallocate the decompression state. The use of Z_FINISH williamr@2: is never required, but can be used to inform inflate that a faster routine williamr@2: may be used for the single inflate() call. williamr@2: williamr@2: If a preset dictionary is needed at this point (see inflateSetDictionary williamr@2: below), inflate sets strm-adler to the adler32 checksum of the williamr@2: dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise williamr@2: it sets strm->adler to the adler32 checksum of all output produced williamr@2: so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or williamr@2: an error code as described below. At the end of the stream, inflate() williamr@2: checks that its computed adler32 checksum is equal to that saved by the williamr@2: compressor and returns Z_STREAM_END only if the checksum is correct. williamr@2: williamr@2: inflate() returns Z_OK if some progress has been made (more input processed williamr@2: or more output produced), Z_STREAM_END if the end of the compressed data has williamr@2: been reached and all uncompressed output has been produced, Z_NEED_DICT if a williamr@2: preset dictionary is needed at this point, Z_DATA_ERROR if the input data was williamr@2: corrupted (input stream not conforming to the zlib format or incorrect williamr@2: adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent williamr@2: (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not williamr@2: enough memory, Z_BUF_ERROR if no progress is possible or if there was not williamr@2: enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR williamr@2: case, the application may then call inflateSync to look for a good williamr@2: compression block. williamr@2: */ williamr@2: williamr@2: williamr@2: ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); williamr@2: /* williamr@2: All dynamically allocated data structures for this stream are freed. williamr@2: This function discards any unprocessed input and does not flush any williamr@2: pending output. williamr@2: williamr@2: inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state williamr@2: was inconsistent. In the error case, msg may be set but then points to a williamr@2: static string (which must not be deallocated). williamr@2: */ williamr@2: williamr@2: /* Advanced functions */ williamr@2: williamr@2: /* williamr@2: The following functions are needed only in some special applications. williamr@2: */ williamr@2: williamr@2: /* williamr@2: ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, williamr@2: int level, williamr@2: int method, williamr@2: int windowBits, williamr@2: int memLevel, williamr@2: int strategy)); williamr@2: williamr@2: This is another version of deflateInit with more compression options. The williamr@2: fields next_in, zalloc, zfree and opaque must be initialized before by williamr@2: the caller. williamr@2: williamr@2: The method parameter is the compression method. It must be Z_DEFLATED in williamr@2: this version of the library. williamr@2: williamr@2: The windowBits parameter is the base two logarithm of the window size williamr@2: (the size of the history buffer). It should be in the range 8..15 for this williamr@2: version of the library. Larger values of this parameter result in better williamr@2: compression at the expense of memory usage. The default value is 15 if williamr@2: deflateInit is used instead. williamr@2: williamr@2: The memLevel parameter specifies how much memory should be allocated williamr@2: for the internal compression state. memLevel=1 uses minimum memory but williamr@2: is slow and reduces compression ratio; memLevel=9 uses maximum memory williamr@2: for optimal speed. The default value is 8. See zconf.h for total memory williamr@2: usage as a function of windowBits and memLevel. williamr@2: williamr@2: The strategy parameter is used to tune the compression algorithm. Use the williamr@2: value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a williamr@2: filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no williamr@2: string match). Filtered data consists mostly of small values with a williamr@2: somewhat random distribution. In this case, the compression algorithm is williamr@2: tuned to compress them better. The effect of Z_FILTERED is to force more williamr@2: Huffman coding and less string matching; it is somewhat intermediate williamr@2: between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects williamr@2: the compression ratio but not the correctness of the compressed output even williamr@2: if it is not set appropriately. williamr@2: williamr@2: deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough williamr@2: memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid williamr@2: method). msg is set to null if there is no error message. deflateInit2 does williamr@2: not perform any compression: this will be done by deflate(). williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, williamr@2: const Bytef *dictionary, williamr@2: uInt dictLength)); williamr@2: /* williamr@2: Initializes the compression dictionary from the given byte sequence williamr@2: without producing any compressed output. This function must be called williamr@2: immediately after deflateInit, deflateInit2 or deflateReset, before any williamr@2: call of deflate. The compressor and decompressor must use exactly the same williamr@2: dictionary (see inflateSetDictionary). williamr@2: williamr@2: The dictionary should consist of strings (byte sequences) that are likely williamr@2: to be encountered later in the data to be compressed, with the most commonly williamr@2: used strings preferably put towards the end of the dictionary. Using a williamr@2: dictionary is most useful when the data to be compressed is short and can be williamr@2: predicted with good accuracy; the data can then be compressed better than williamr@2: with the default empty dictionary. williamr@2: williamr@2: Depending on the size of the compression data structures selected by williamr@2: deflateInit or deflateInit2, a part of the dictionary may in effect be williamr@2: discarded, for example if the dictionary is larger than the window size in williamr@2: deflate or deflate2. Thus the strings most likely to be useful should be williamr@2: put at the end of the dictionary, not at the front. williamr@2: williamr@2: Upon return of this function, strm->adler is set to the Adler32 value williamr@2: of the dictionary; the decompressor may later use this value to determine williamr@2: which dictionary has been used by the compressor. (The Adler32 value williamr@2: applies to the whole dictionary even if only a subset of the dictionary is williamr@2: actually used by the compressor.) williamr@2: williamr@2: deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a williamr@2: parameter is invalid (such as NULL dictionary) or the stream state is williamr@2: inconsistent (for example if deflate has already been called for this stream williamr@2: or if the compression method is bsort). deflateSetDictionary does not williamr@2: perform any compression: this will be done by deflate(). williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, williamr@2: z_streamp source)); williamr@2: /* williamr@2: Sets the destination stream as a complete copy of the source stream. williamr@2: williamr@2: This function can be useful when several compression strategies will be williamr@2: tried, for example when there are several ways of pre-processing the input williamr@2: data with a filter. The streams that will be discarded should then be freed williamr@2: by calling deflateEnd. Note that deflateCopy duplicates the internal williamr@2: compression state which can be quite large, so this strategy is slow and williamr@2: can consume lots of memory. williamr@2: williamr@2: deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not williamr@2: enough memory, Z_STREAM_ERROR if the source stream state was inconsistent williamr@2: (such as zalloc being NULL). msg is left unchanged in both source and williamr@2: destination. williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); williamr@2: /* williamr@2: This function is equivalent to deflateEnd followed by deflateInit, williamr@2: but does not free and reallocate all the internal compression state. williamr@2: The stream will keep the same compression level and any other attributes williamr@2: that may have been set by deflateInit2. williamr@2: williamr@2: deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source williamr@2: stream state was inconsistent (such as zalloc or state being NULL). williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, williamr@2: int level, williamr@2: int strategy)); williamr@2: /* williamr@2: Dynamically update the compression level and compression strategy. The williamr@2: interpretation of level and strategy is as in deflateInit2. This can be williamr@2: used to switch between compression and straight copy of the input data, or williamr@2: to switch to a different kind of input data requiring a different williamr@2: strategy. If the compression level is changed, the input available so far williamr@2: is compressed with the old level (and may be flushed); the new level will williamr@2: take effect only at the next call of deflate(). williamr@2: williamr@2: Before the call of deflateParams, the stream state must be set as for williamr@2: a call of deflate(), since the currently available input may have to williamr@2: be compressed and flushed. In particular, strm->avail_out must be non-zero. williamr@2: williamr@2: deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source williamr@2: stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR williamr@2: if strm->avail_out was zero. williamr@2: */ williamr@2: williamr@2: /* williamr@2: ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, williamr@2: int windowBits)); williamr@2: williamr@2: This is another version of inflateInit with an extra parameter. The williamr@2: fields next_in, avail_in, zalloc, zfree and opaque must be initialized williamr@2: before by the caller. williamr@2: williamr@2: The windowBits parameter is the base two logarithm of the maximum window williamr@2: size (the size of the history buffer). It should be in the range 8..15 for williamr@2: this version of the library. The default value is 15 if inflateInit is used williamr@2: instead. If a compressed stream with a larger window size is given as williamr@2: input, inflate() will return with the error code Z_DATA_ERROR instead of williamr@2: trying to allocate a larger window. williamr@2: williamr@2: inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough williamr@2: memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative williamr@2: memLevel). msg is set to null if there is no error message. inflateInit2 williamr@2: does not perform any decompression apart from reading the zlib header if williamr@2: present: this will be done by inflate(). (So next_in and avail_in may be williamr@2: modified, but next_out and avail_out are unchanged.) williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, williamr@2: const Bytef *dictionary, williamr@2: uInt dictLength)); williamr@2: /* williamr@2: Initializes the decompression dictionary from the given uncompressed byte williamr@2: sequence. This function must be called immediately after a call of inflate williamr@2: if this call returned Z_NEED_DICT. The dictionary chosen by the compressor williamr@2: can be determined from the Adler32 value returned by this call of williamr@2: inflate. The compressor and decompressor must use exactly the same williamr@2: dictionary (see deflateSetDictionary). williamr@2: williamr@2: inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a williamr@2: parameter is invalid (such as NULL dictionary) or the stream state is williamr@2: inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the williamr@2: expected one (incorrect Adler32 value). inflateSetDictionary does not williamr@2: perform any decompression: this will be done by subsequent calls of williamr@2: inflate(). williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); williamr@2: /* williamr@2: Skips invalid compressed data until a full flush point (see above the williamr@2: description of deflate with Z_FULL_FLUSH) can be found, or until all williamr@2: available input is skipped. No output is provided. williamr@2: williamr@2: inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR williamr@2: if no more input was provided, Z_DATA_ERROR if no flush point has been found, williamr@2: or Z_STREAM_ERROR if the stream structure was inconsistent. In the success williamr@2: case, the application may save the current current value of total_in which williamr@2: indicates where valid compressed data was found. In the error case, the williamr@2: application may repeatedly call inflateSync, providing more input each time, williamr@2: until success or end of the input data. williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); williamr@2: /* williamr@2: This function is equivalent to inflateEnd followed by inflateInit, williamr@2: but does not free and reallocate all the internal decompression state. williamr@2: The stream will keep attributes that may have been set by inflateInit2. williamr@2: williamr@2: inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source williamr@2: stream state was inconsistent (such as zalloc or state being NULL). williamr@2: */ williamr@2: williamr@2: williamr@2: /* utility functions */ williamr@2: williamr@2: /* williamr@2: The following utility functions are implemented on top of the williamr@2: basic stream-oriented functions. To simplify the interface, some williamr@2: default options are assumed (compression level and memory usage, williamr@2: standard memory allocation functions). The source code of these williamr@2: utility functions can easily be modified if you need special options. williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, williamr@2: const Bytef *source, uLong sourceLen)); williamr@2: /* williamr@2: Compresses the source buffer into the destination buffer. sourceLen is williamr@2: the byte length of the source buffer. Upon entry, destLen is the total williamr@2: size of the destination buffer, which must be at least 0.1% larger than williamr@2: sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the williamr@2: compressed buffer. williamr@2: This function can be used to compress a whole file at once if the williamr@2: input file is mmap'ed. williamr@2: compress returns Z_OK if success, Z_MEM_ERROR if there was not williamr@2: enough memory, Z_BUF_ERROR if there was not enough room in the output williamr@2: buffer. williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, williamr@2: const Bytef *source, uLong sourceLen, williamr@2: int level)); williamr@2: /* williamr@2: Compresses the source buffer into the destination buffer. The level williamr@2: parameter has the same meaning as in deflateInit. sourceLen is the byte williamr@2: length of the source buffer. Upon entry, destLen is the total size of the williamr@2: destination buffer, which must be at least 0.1% larger than sourceLen plus williamr@2: 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. williamr@2: williamr@2: compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough williamr@2: memory, Z_BUF_ERROR if there was not enough room in the output buffer, williamr@2: Z_STREAM_ERROR if the level parameter is invalid. williamr@2: */ williamr@2: williamr@2: ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, williamr@2: const Bytef *source, uLong sourceLen)); williamr@2: /* williamr@2: Decompresses the source buffer into the destination buffer. sourceLen is williamr@2: the byte length of the source buffer. Upon entry, destLen is the total williamr@2: size of the destination buffer, which must be large enough to hold the williamr@2: entire uncompressed data. (The size of the uncompressed data must have williamr@2: been saved previously by the compressor and transmitted to the decompressor williamr@2: by some mechanism outside the scope of this compression library.) williamr@2: Upon exit, destLen is the actual size of the compressed buffer. williamr@2: This function can be used to decompress a whole file at once if the williamr@2: input file is mmap'ed. williamr@2: williamr@2: uncompress returns Z_OK if success, Z_MEM_ERROR if there was not williamr@2: enough memory, Z_BUF_ERROR if there was not enough room in the output williamr@2: buffer, or Z_DATA_ERROR if the input data was corrupted. williamr@2: */ williamr@2: williamr@2: /* williamr@2: typedef voidp gzFile; williamr@2: williamr@2: ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); williamr@2: */ williamr@2: /* williamr@2: Opens a gzip (.gz) file for reading or writing. The mode parameter williamr@2: is as in fopen ("rb" or "wb") but can also include a compression level williamr@2: ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for williamr@2: Huffman only compression as in "wb1h". (See the description williamr@2: of deflateInit2 for more information about the strategy parameter.) williamr@2: williamr@2: gzopen can be used to read a file which is not in gzip format; in this williamr@2: case gzread will directly read from the file without decompression. williamr@2: williamr@2: gzopen returns NULL if the file could not be opened or if there was williamr@2: insufficient memory to allocate the (de)compression state; errno williamr@2: can be checked to distinguish the two cases (if errno is zero, the williamr@2: zlib error is Z_MEM_ERROR). */ williamr@2: williamr@2: //ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); williamr@2: williamr@2: /* williamr@2: gzdopen() associates a gzFile with the file descriptor fd. File williamr@2: descriptors are obtained from calls like open, dup, creat, pipe or williamr@2: fileno (in the file has been previously opened with fopen). williamr@2: The mode parameter is as in gzopen. williamr@2: The next call of gzclose on the returned gzFile will also close the williamr@2: file descriptor fd, just like fclose(fdopen(fd), mode) closes the file williamr@2: descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). williamr@2: gzdopen returns NULL if there was insufficient memory to allocate williamr@2: the (de)compression state. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); williamr@2: /* williamr@2: Dynamically update the compression level or strategy. See the description williamr@2: of deflateInit2 for the meaning of these parameters. williamr@2: gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not williamr@2: opened for writing. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); williamr@2: /* williamr@2: Reads the given number of uncompressed bytes from the compressed file. williamr@2: If the input file was not in gzip format, gzread copies the given number williamr@2: of bytes into the buffer. williamr@2: gzread returns the number of uncompressed bytes actually read (0 for williamr@2: end of file, -1 for error). */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzwrite OF((gzFile file, williamr@2: // const voidp buf, unsigned len)); williamr@2: /* williamr@2: Writes the given number of uncompressed bytes into the compressed file. williamr@2: gzwrite returns the number of uncompressed bytes actually written williamr@2: (0 in case of error). williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); williamr@2: /* williamr@2: Converts, formats, and writes the args to the compressed file under williamr@2: control of the format string, as in fprintf. gzprintf returns the number of williamr@2: uncompressed bytes actually written (0 in case of error). williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); williamr@2: /* williamr@2: Writes the given null-terminated string to the compressed file, excluding williamr@2: the terminating null character. williamr@2: gzputs returns the number of characters written, or -1 in case of error. williamr@2: */ williamr@2: williamr@2: //ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); williamr@2: /* williamr@2: Reads bytes from the compressed file until len-1 characters are read, or williamr@2: a newline character is read and transferred to buf, or an end-of-file williamr@2: condition is encountered. The string is then terminated with a null williamr@2: character. williamr@2: gzgets returns buf, or Z_NULL in case of error. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); williamr@2: /* williamr@2: Writes c, converted to an unsigned char, into the compressed file. williamr@2: gzputc returns the value that was written, or -1 in case of error. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); williamr@2: /* williamr@2: Reads one byte from the compressed file. gzgetc returns this byte williamr@2: or -1 in case of end of file or error. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); williamr@2: /* williamr@2: Flushes all pending output into the compressed file. The parameter williamr@2: flush is as in the deflate() function. The return value is the zlib williamr@2: error number (see function gzerror below). gzflush returns Z_OK if williamr@2: the flush parameter is Z_FINISH and all output could be flushed. williamr@2: gzflush should be called only when strictly necessary because it can williamr@2: degrade compression. williamr@2: */ williamr@2: williamr@2: //ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, williamr@2: // z_off_t offset, int whence)); williamr@2: /* williamr@2: Sets the starting position for the next gzread or gzwrite on the williamr@2: given compressed file. The offset represents a number of bytes in the williamr@2: uncompressed data stream. The whence parameter is defined as in lseek(2); williamr@2: the value SEEK_END is not supported. williamr@2: If the file is opened for reading, this function is emulated but can be williamr@2: extremely slow. If the file is opened for writing, only forward seeks are williamr@2: supported; gzseek then compresses a sequence of zeroes up to the new williamr@2: starting position. williamr@2: williamr@2: gzseek returns the resulting offset location as measured in bytes from williamr@2: the beginning of the uncompressed stream, or -1 in case of error, in williamr@2: particular if the file is opened for writing and the new starting position williamr@2: would be before the current position. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); williamr@2: /* williamr@2: Rewinds the given file. This function is supported only for reading. williamr@2: williamr@2: gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) williamr@2: */ williamr@2: williamr@2: //ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); williamr@2: /* williamr@2: Returns the starting position for the next gzread or gzwrite on the williamr@2: given compressed file. This position represents a number of bytes in the williamr@2: uncompressed data stream. williamr@2: williamr@2: gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzeof OF((gzFile file)); williamr@2: /* williamr@2: Returns 1 when EOF has previously been detected reading the given williamr@2: input stream, otherwise zero. williamr@2: */ williamr@2: williamr@2: //ZEXTERN int ZEXPORT gzclose OF((gzFile file)); williamr@2: /* williamr@2: Flushes all pending output if necessary, closes the compressed file williamr@2: and deallocates all the (de)compression state. The return value is the zlib williamr@2: error number (see function gzerror below). williamr@2: */ williamr@2: williamr@2: //ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); williamr@2: /* williamr@2: Returns the error message for the last error which occurred on the williamr@2: given compressed file. errnum is set to zlib error number. If an williamr@2: error occurred in the file system and not in the compression library, williamr@2: errnum is set to Z_ERRNO and the application may consult errno williamr@2: to get the exact error code. williamr@2: */ williamr@2: williamr@2: /* checksum functions */ williamr@2: williamr@2: /* williamr@2: These functions are not related to compression but are exported williamr@2: anyway because they might be useful in applications using the williamr@2: compression library. williamr@2: */ williamr@2: williamr@2: ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); williamr@2: williamr@2: /* williamr@2: Update a running Adler-32 checksum with the bytes buf[0..len-1] and williamr@2: return the updated checksum. If buf is NULL, this function returns williamr@2: the required initial value for the checksum. williamr@2: An Adler-32 checksum is almost as reliable as a CRC32 but can be computed williamr@2: much faster. Usage example: williamr@2: williamr@2: uLong adler = adler32(0L, Z_NULL, 0); williamr@2: williamr@2: while (read_buffer(buffer, length) != EOF) { williamr@2: adler = adler32(adler, buffer, length); williamr@2: } williamr@2: if (adler != original_adler) error(); williamr@2: */ williamr@2: williamr@2: ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); williamr@2: /* williamr@2: Update a running crc with the bytes buf[0..len-1] and return the updated williamr@2: crc. If buf is NULL, this function returns the required initial value williamr@2: for the crc. Pre- and post-conditioning (one's complement) is performed williamr@2: within this function so it shouldn't be done by the application. williamr@2: Usage example: williamr@2: williamr@2: uLong crc = crc32(0L, Z_NULL, 0); williamr@2: williamr@2: while (read_buffer(buffer, length) != EOF) { williamr@2: crc = crc32(crc, buffer, length); williamr@2: } williamr@2: if (crc != original_crc) error(); williamr@2: */ williamr@2: williamr@2: williamr@2: /* various hacks, don't look :) */ williamr@2: williamr@2: /* deflateInit and inflateInit are macros to allow checking the zlib version williamr@2: * and the compiler's view of z_stream: williamr@2: */ williamr@2: ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, williamr@2: const char *version, int stream_size)); williamr@2: ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, williamr@2: const char *version, int stream_size)); williamr@2: ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, williamr@2: int windowBits, int memLevel, williamr@2: int strategy, const char *version, williamr@2: int stream_size)); williamr@2: ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, williamr@2: const char *version, int stream_size)); williamr@2: #define deflateInit(strm, level) \ williamr@2: deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) williamr@2: #define inflateInit(strm) \ williamr@2: inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) williamr@2: #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ williamr@2: deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ williamr@2: (strategy), ZLIB_VERSION, sizeof(z_stream)) williamr@2: #define inflateInit2(strm, windowBits) \ williamr@2: inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) williamr@2: williamr@2: williamr@2: #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: */ williamr@2: struct internal_state {int dummy;}; /* hack for buggy compilers */ williamr@2: #endif williamr@2: williamr@2: ZEXTERN const char * ZEXPORT zError OF((int err)); williamr@2: ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); williamr@2: ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); williamr@2: williamr@2: #ifdef __cplusplus williamr@2: } williamr@2: #endif williamr@2: williamr@2: #endif /* _ZLIB_H */