Back to index

avfs  1.0.1
zlib.h
Go to the documentation of this file.
00001 /* IMPORTANT NOTE: This is not the original zlib distribution. The
00002    following files have been modified:
00003    
00004    infblock.c
00005    infblock.h
00006    infcodes.c
00007    infcodes.h
00008    inflate.c
00009    zlib.h
00010 
00011    The modifications are copyright (C) 2001 Miklos Szeredi
00012    <miklos@szeredi.hu>
00013 
00014    The modified software can be distributed under the same licence as
00015    the original software (see bellow).
00016 */
00017 
00018 /* zlib.h -- interface of the 'zlib' general purpose compression library
00019   version 1.1.4, March 11th, 2002
00020 
00021   Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
00022 
00023   This software is provided 'as-is', without any express or implied
00024   warranty.  In no event will the authors be held liable for any damages
00025   arising from the use of this software.
00026 
00027   Permission is granted to anyone to use this software for any purpose,
00028   including commercial applications, and to alter it and redistribute it
00029   freely, subject to the following restrictions:
00030 
00031   1. The origin of this software must not be misrepresented; you must not
00032      claim that you wrote the original software. If you use this software
00033      in a product, an acknowledgment in the product documentation would be
00034      appreciated but is not required.
00035   2. Altered source versions must be plainly marked as such, and must not be
00036      misrepresented as being the original software.
00037   3. This notice may not be removed or altered from any source distribution.
00038 
00039   Jean-loup Gailly        Mark Adler
00040   jloup@gzip.org          madler@alumni.caltech.edu
00041 
00042 
00043   The data format used by the zlib library is described by RFCs (Request for
00044   Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
00045   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
00046 */
00047 
00048 #ifndef _ZLIB_H
00049 #define _ZLIB_H
00050 
00051 #include "zconf.h"
00052 
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056 
00057 #define ZLIB_VERSION "1.1.4"
00058 
00059 /* 
00060      The 'zlib' compression library provides in-memory compression and
00061   decompression functions, including integrity checks of the uncompressed
00062   data.  This version of the library supports only one compression method
00063   (deflation) but other algorithms will be added later and will have the same
00064   stream interface.
00065 
00066      Compression can be done in a single step if the buffers are large
00067   enough (for example if an input file is mmap'ed), or can be done by
00068   repeated calls of the compression function.  In the latter case, the
00069   application must provide more input and/or consume the output
00070   (providing more output space) before each call.
00071 
00072      The library also supports reading and writing files in gzip (.gz) format
00073   with an interface similar to that of stdio.
00074 
00075      The library does not install any signal handler. The decoder checks
00076   the consistency of the compressed data, so the library should never
00077   crash even in case of corrupted input.
00078 */
00079 
00080 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
00081 typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
00082 
00083 struct internal_state;
00084 
00085 typedef struct z_stream_s {
00086     Bytef    *next_in;  /* next input byte */
00087     uInt     avail_in;  /* number of bytes available at next_in */
00088     uLongLong total_in;  /* total nb of input bytes read so far */
00089 
00090     Bytef    *next_out; /* next output byte should be put there */
00091     uInt     avail_out; /* remaining free space at next_out */
00092     uLongLong total_out; /* total nb of bytes output so far */
00093 
00094     char     *msg;      /* last error message, NULL if no error */
00095     struct internal_state FAR *state; /* not visible by applications */
00096 
00097     alloc_func zalloc;  /* used to allocate the internal state */
00098     free_func  zfree;   /* used to free the internal state */
00099     voidpf     opaque;  /* private data object passed to zalloc and zfree */
00100 
00101     int     data_type;  /* best guess about the data type: ascii or binary */
00102     uLong   adler;      /* adler32 value of the uncompressed data */
00103     uLong   reserved;   /* reserved for future use */
00104 } z_stream;
00105 
00106 typedef z_stream FAR *z_streamp;
00107 
00108 /*
00109    The application must update next_in and avail_in when avail_in has
00110    dropped to zero. It must update next_out and avail_out when avail_out
00111    has dropped to zero. The application must initialize zalloc, zfree and
00112    opaque before calling the init function. All other fields are set by the
00113    compression library and must not be updated by the application.
00114 
00115    The opaque value provided by the application will be passed as the first
00116    parameter for calls of zalloc and zfree. This can be useful for custom
00117    memory management. The compression library attaches no meaning to the
00118    opaque value.
00119 
00120    zalloc must return Z_NULL if there is not enough memory for the object.
00121    If zlib is used in a multi-threaded application, zalloc and zfree must be
00122    thread safe.
00123 
00124    On 16-bit systems, the functions zalloc and zfree must be able to allocate
00125    exactly 65536 bytes, but will not be required to allocate more than this
00126    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
00127    pointers returned by zalloc for objects of exactly 65536 bytes *must*
00128    have their offset normalized to zero. The default allocation function
00129    provided by this library ensures this (see zutil.c). To reduce memory
00130    requirements and avoid any allocation of 64K objects, at the expense of
00131    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
00132 
00133    The fields total_in and total_out can be used for statistics or
00134    progress reports. After compression, total_in holds the total size of
00135    the uncompressed data and may be saved for use in the decompressor
00136    (particularly if the decompressor wants to decompress everything in
00137    a single step).
00138 */
00139 
00140                         /* constants */
00141 
00142 #define Z_NO_FLUSH      0
00143 #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
00144 #define Z_SYNC_FLUSH    2
00145 #define Z_FULL_FLUSH    3
00146 #define Z_FINISH        4
00147 /* Allowed flush values; see deflate() below for details */
00148 
00149 #define Z_OK            0
00150 #define Z_STREAM_END    1
00151 #define Z_NEED_DICT     2
00152 #define Z_ERRNO        (-1)
00153 #define Z_STREAM_ERROR (-2)
00154 #define Z_DATA_ERROR   (-3)
00155 #define Z_MEM_ERROR    (-4)
00156 #define Z_BUF_ERROR    (-5)
00157 #define Z_VERSION_ERROR (-6)
00158 /* Return codes for the compression/decompression functions. Negative
00159  * values are errors, positive values are used for special but normal events.
00160  */
00161 
00162 #define Z_NO_COMPRESSION         0
00163 #define Z_BEST_SPEED             1
00164 #define Z_BEST_COMPRESSION       9
00165 #define Z_DEFAULT_COMPRESSION  (-1)
00166 /* compression levels */
00167 
00168 #define Z_FILTERED            1
00169 #define Z_HUFFMAN_ONLY        2
00170 #define Z_DEFAULT_STRATEGY    0
00171 /* compression strategy; see deflateInit2() below for details */
00172 
00173 #define Z_BINARY   0
00174 #define Z_ASCII    1
00175 #define Z_UNKNOWN  2
00176 /* Possible values of the data_type field */
00177 
00178 #define Z_DEFLATED   8
00179 /* The deflate compression method (the only one supported in this version) */
00180 
00181 #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
00182 
00183 #define zlib_version zlibVersion()
00184 /* for compatibility with versions < 1.0.2 */
00185 
00186                         /* basic functions */
00187 
00188 ZEXTERN const char * ZEXPORT zlibVersion OF((void));
00189 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
00190    If the first character differs, the library code actually used is
00191    not compatible with the zlib.h header file used by the application.
00192    This check is automatically made by deflateInit and inflateInit.
00193  */
00194 
00195 /* 
00196 ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
00197 
00198      Initializes the internal stream state for compression. The fields
00199    zalloc, zfree and opaque must be initialized before by the caller.
00200    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
00201    use default allocation functions.
00202 
00203      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
00204    1 gives best speed, 9 gives best compression, 0 gives no compression at
00205    all (the input data is simply copied a block at a time).
00206    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
00207    compression (currently equivalent to level 6).
00208 
00209      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
00210    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
00211    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
00212    with the version assumed by the caller (ZLIB_VERSION).
00213    msg is set to null if there is no error message.  deflateInit does not
00214    perform any compression: this will be done by deflate().
00215 */
00216 
00217 
00218 ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
00219 /*
00220     deflate compresses as much data as possible, and stops when the input
00221   buffer becomes empty or the output buffer becomes full. It may introduce some
00222   output latency (reading input without producing any output) except when
00223   forced to flush.
00224 
00225     The detailed semantics are as follows. deflate performs one or both of the
00226   following actions:
00227 
00228   - Compress more input starting at next_in and update next_in and avail_in
00229     accordingly. If not all input can be processed (because there is not
00230     enough room in the output buffer), next_in and avail_in are updated and
00231     processing will resume at this point for the next call of deflate().
00232 
00233   - Provide more output starting at next_out and update next_out and avail_out
00234     accordingly. This action is forced if the parameter flush is non zero.
00235     Forcing flush frequently degrades the compression ratio, so this parameter
00236     should be set only when necessary (in interactive applications).
00237     Some output may be provided even if flush is not set.
00238 
00239   Before the call of deflate(), the application should ensure that at least
00240   one of the actions is possible, by providing more input and/or consuming
00241   more output, and updating avail_in or avail_out accordingly; avail_out
00242   should never be zero before the call. The application can consume the
00243   compressed output when it wants, for example when the output buffer is full
00244   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
00245   and with zero avail_out, it must be called again after making room in the
00246   output buffer because there might be more output pending.
00247 
00248     If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
00249   flushed to the output buffer and the output is aligned on a byte boundary, so
00250   that the decompressor can get all input data available so far. (In particular
00251   avail_in is zero after the call if enough output space has been provided
00252   before the call.)  Flushing may degrade compression for some compression
00253   algorithms and so it should be used only when necessary.
00254 
00255     If flush is set to Z_FULL_FLUSH, all output is flushed as with
00256   Z_SYNC_FLUSH, and the compression state is reset so that decompression can
00257   restart from this point if previous compressed data has been damaged or if
00258   random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
00259   the compression.
00260 
00261     If deflate returns with avail_out == 0, this function must be called again
00262   with the same value of the flush parameter and more output space (updated
00263   avail_out), until the flush is complete (deflate returns with non-zero
00264   avail_out).
00265 
00266     If the parameter flush is set to Z_FINISH, pending input is processed,
00267   pending output is flushed and deflate returns with Z_STREAM_END if there
00268   was enough output space; if deflate returns with Z_OK, this function must be
00269   called again with Z_FINISH and more output space (updated avail_out) but no
00270   more input data, until it returns with Z_STREAM_END or an error. After
00271   deflate has returned Z_STREAM_END, the only possible operations on the
00272   stream are deflateReset or deflateEnd.
00273   
00274     Z_FINISH can be used immediately after deflateInit if all the compression
00275   is to be done in a single step. In this case, avail_out must be at least
00276   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
00277   Z_STREAM_END, then it must be called again as described above.
00278 
00279     deflate() sets strm->adler to the adler32 checksum of all input read
00280   so far (that is, total_in bytes).
00281 
00282     deflate() may update data_type if it can make a good guess about
00283   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
00284   binary. This field is only for information purposes and does not affect
00285   the compression algorithm in any manner.
00286 
00287     deflate() returns Z_OK if some progress has been made (more input
00288   processed or more output produced), Z_STREAM_END if all input has been
00289   consumed and all output has been produced (only when flush is set to
00290   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
00291   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
00292   (for example avail_in or avail_out was zero).
00293 */
00294 
00295 
00296 ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
00297 /*
00298      All dynamically allocated data structures for this stream are freed.
00299    This function discards any unprocessed input and does not flush any
00300    pending output.
00301 
00302      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
00303    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
00304    prematurely (some input or output was discarded). In the error case,
00305    msg may be set but then points to a static string (which must not be
00306    deallocated).
00307 */
00308 
00309 
00310 /* 
00311 ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
00312 
00313      Initializes the internal stream state for decompression. The fields
00314    next_in, avail_in, zalloc, zfree and opaque must be initialized before by
00315    the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
00316    value depends on the compression method), inflateInit determines the
00317    compression method from the zlib header and allocates all data structures
00318    accordingly; otherwise the allocation will be deferred to the first call of
00319    inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
00320    use default allocation functions.
00321 
00322      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
00323    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
00324    version assumed by the caller.  msg is set to null if there is no error
00325    message. inflateInit does not perform any decompression apart from reading
00326    the zlib header if present: this will be done by inflate().  (So next_in and
00327    avail_in may be modified, but next_out and avail_out are unchanged.)
00328 */
00329 
00330 
00331 ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
00332 /*
00333     inflate decompresses as much data as possible, and stops when the input
00334   buffer becomes empty or the output buffer becomes full. It may some
00335   introduce some output latency (reading input without producing any output)
00336   except when forced to flush.
00337 
00338   The detailed semantics are as follows. inflate performs one or both of the
00339   following actions:
00340 
00341   - Decompress more input starting at next_in and update next_in and avail_in
00342     accordingly. If not all input can be processed (because there is not
00343     enough room in the output buffer), next_in is updated and processing
00344     will resume at this point for the next call of inflate().
00345 
00346   - Provide more output starting at next_out and update next_out and avail_out
00347     accordingly.  inflate() provides as much output as possible, until there
00348     is no more input data or no more space in the output buffer (see below
00349     about the flush parameter).
00350 
00351   Before the call of inflate(), the application should ensure that at least
00352   one of the actions is possible, by providing more input and/or consuming
00353   more output, and updating the next_* and avail_* values accordingly.
00354   The application can consume the uncompressed output when it wants, for
00355   example when the output buffer is full (avail_out == 0), or after each
00356   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
00357   must be called again after making room in the output buffer because there
00358   might be more output pending.
00359 
00360     If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
00361   output as possible to the output buffer. The flushing behavior of inflate is
00362   not specified for values of the flush parameter other than Z_SYNC_FLUSH
00363   and Z_FINISH, but the current implementation actually flushes as much output
00364   as possible anyway.
00365 
00366     inflate() should normally be called until it returns Z_STREAM_END or an
00367   error. However if all decompression is to be performed in a single step
00368   (a single call of inflate), the parameter flush should be set to
00369   Z_FINISH. In this case all pending input is processed and all pending
00370   output is flushed; avail_out must be large enough to hold all the
00371   uncompressed data. (The size of the uncompressed data may have been saved
00372   by the compressor for this purpose.) The next operation on this stream must
00373   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
00374   is never required, but can be used to inform inflate that a faster routine
00375   may be used for the single inflate() call.
00376 
00377      If a preset dictionary is needed at this point (see inflateSetDictionary
00378   below), inflate sets strm-adler to the adler32 checksum of the
00379   dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise 
00380   it sets strm->adler to the adler32 checksum of all output produced
00381   so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
00382   an error code as described below. At the end of the stream, inflate()
00383   checks that its computed adler32 checksum is equal to that saved by the
00384   compressor and returns Z_STREAM_END only if the checksum is correct.
00385 
00386     inflate() returns Z_OK if some progress has been made (more input processed
00387   or more output produced), Z_STREAM_END if the end of the compressed data has
00388   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
00389   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
00390   corrupted (input stream not conforming to the zlib format or incorrect
00391   adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
00392   (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
00393   enough memory, Z_BUF_ERROR if no progress is possible or if there was not
00394   enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
00395   case, the application may then call inflateSync to look for a good
00396   compression block.
00397 */
00398 
00399 
00400 ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
00401 /*
00402      All dynamically allocated data structures for this stream are freed.
00403    This function discards any unprocessed input and does not flush any
00404    pending output.
00405 
00406      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
00407    was inconsistent. In the error case, msg may be set but then points to a
00408    static string (which must not be deallocated).
00409 */
00410 
00411                         /* Advanced functions */
00412 
00413 /*
00414     The following functions are needed only in some special applications.
00415 */
00416 
00417 /*   
00418 ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
00419                                      int  level,
00420                                      int  method,
00421                                      int  windowBits,
00422                                      int  memLevel,
00423                                      int  strategy));
00424 
00425      This is another version of deflateInit with more compression options. The
00426    fields next_in, zalloc, zfree and opaque must be initialized before by
00427    the caller.
00428 
00429      The method parameter is the compression method. It must be Z_DEFLATED in
00430    this version of the library.
00431 
00432      The windowBits parameter is the base two logarithm of the window size
00433    (the size of the history buffer).  It should be in the range 8..15 for this
00434    version of the library. Larger values of this parameter result in better
00435    compression at the expense of memory usage. The default value is 15 if
00436    deflateInit is used instead.
00437 
00438      The memLevel parameter specifies how much memory should be allocated
00439    for the internal compression state. memLevel=1 uses minimum memory but
00440    is slow and reduces compression ratio; memLevel=9 uses maximum memory
00441    for optimal speed. The default value is 8. See zconf.h for total memory
00442    usage as a function of windowBits and memLevel.
00443 
00444      The strategy parameter is used to tune the compression algorithm. Use the
00445    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
00446    filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
00447    string match).  Filtered data consists mostly of small values with a
00448    somewhat random distribution. In this case, the compression algorithm is
00449    tuned to compress them better. The effect of Z_FILTERED is to force more
00450    Huffman coding and less string matching; it is somewhat intermediate
00451    between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
00452    the compression ratio but not the correctness of the compressed output even
00453    if it is not set appropriately.
00454 
00455       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
00456    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
00457    method). msg is set to null if there is no error message.  deflateInit2 does
00458    not perform any compression: this will be done by deflate().
00459 */
00460                             
00461 ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
00462                                              const Bytef *dictionary,
00463                                              uInt  dictLength));
00464 /*
00465      Initializes the compression dictionary from the given byte sequence
00466    without producing any compressed output. This function must be called
00467    immediately after deflateInit, deflateInit2 or deflateReset, before any
00468    call of deflate. The compressor and decompressor must use exactly the same
00469    dictionary (see inflateSetDictionary).
00470 
00471      The dictionary should consist of strings (byte sequences) that are likely
00472    to be encountered later in the data to be compressed, with the most commonly
00473    used strings preferably put towards the end of the dictionary. Using a
00474    dictionary is most useful when the data to be compressed is short and can be
00475    predicted with good accuracy; the data can then be compressed better than
00476    with the default empty dictionary.
00477 
00478      Depending on the size of the compression data structures selected by
00479    deflateInit or deflateInit2, a part of the dictionary may in effect be
00480    discarded, for example if the dictionary is larger than the window size in
00481    deflate or deflate2. Thus the strings most likely to be useful should be
00482    put at the end of the dictionary, not at the front.
00483 
00484      Upon return of this function, strm->adler is set to the Adler32 value
00485    of the dictionary; the decompressor may later use this value to determine
00486    which dictionary has been used by the compressor. (The Adler32 value
00487    applies to the whole dictionary even if only a subset of the dictionary is
00488    actually used by the compressor.)
00489 
00490      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
00491    parameter is invalid (such as NULL dictionary) or the stream state is
00492    inconsistent (for example if deflate has already been called for this stream
00493    or if the compression method is bsort). deflateSetDictionary does not
00494    perform any compression: this will be done by deflate().
00495 */
00496 
00497 ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
00498                                     z_streamp source));
00499 /*
00500      Sets the destination stream as a complete copy of the source stream.
00501 
00502      This function can be useful when several compression strategies will be
00503    tried, for example when there are several ways of pre-processing the input
00504    data with a filter. The streams that will be discarded should then be freed
00505    by calling deflateEnd.  Note that deflateCopy duplicates the internal
00506    compression state which can be quite large, so this strategy is slow and
00507    can consume lots of memory.
00508 
00509      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
00510    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
00511    (such as zalloc being NULL). msg is left unchanged in both source and
00512    destination.
00513 */
00514 
00515 ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
00516 /*
00517      This function is equivalent to deflateEnd followed by deflateInit,
00518    but does not free and reallocate all the internal compression state.
00519    The stream will keep the same compression level and any other attributes
00520    that may have been set by deflateInit2.
00521 
00522       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
00523    stream state was inconsistent (such as zalloc or state being NULL).
00524 */
00525 
00526 ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
00527                                   int level,
00528                                   int strategy));
00529 /*
00530      Dynamically update the compression level and compression strategy.  The
00531    interpretation of level and strategy is as in deflateInit2.  This can be
00532    used to switch between compression and straight copy of the input data, or
00533    to switch to a different kind of input data requiring a different
00534    strategy. If the compression level is changed, the input available so far
00535    is compressed with the old level (and may be flushed); the new level will
00536    take effect only at the next call of deflate().
00537 
00538      Before the call of deflateParams, the stream state must be set as for
00539    a call of deflate(), since the currently available input may have to
00540    be compressed and flushed. In particular, strm->avail_out must be non-zero.
00541 
00542      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
00543    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
00544    if strm->avail_out was zero.
00545 */
00546 
00547 /*   
00548 ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
00549                                      int  windowBits));
00550 
00551      This is another version of inflateInit with an extra parameter. The
00552    fields next_in, avail_in, zalloc, zfree and opaque must be initialized
00553    before by the caller.
00554 
00555      The windowBits parameter is the base two logarithm of the maximum window
00556    size (the size of the history buffer).  It should be in the range 8..15 for
00557    this version of the library. The default value is 15 if inflateInit is used
00558    instead. If a compressed stream with a larger window size is given as
00559    input, inflate() will return with the error code Z_DATA_ERROR instead of
00560    trying to allocate a larger window.
00561 
00562       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
00563    memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
00564    memLevel). msg is set to null if there is no error message.  inflateInit2
00565    does not perform any decompression apart from reading the zlib header if
00566    present: this will be done by inflate(). (So next_in and avail_in may be
00567    modified, but next_out and avail_out are unchanged.)
00568 */
00569 
00570 ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
00571                                              const Bytef *dictionary,
00572                                              uInt  dictLength));
00573 /*
00574      Initializes the decompression dictionary from the given uncompressed byte
00575    sequence. This function must be called immediately after a call of inflate
00576    if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
00577    can be determined from the Adler32 value returned by this call of
00578    inflate. The compressor and decompressor must use exactly the same
00579    dictionary (see deflateSetDictionary).
00580 
00581      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
00582    parameter is invalid (such as NULL dictionary) or the stream state is
00583    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
00584    expected one (incorrect Adler32 value). inflateSetDictionary does not
00585    perform any decompression: this will be done by subsequent calls of
00586    inflate().
00587 */
00588 
00589 ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
00590 /* 
00591     Skips invalid compressed data until a full flush point (see above the
00592   description of deflate with Z_FULL_FLUSH) can be found, or until all
00593   available input is skipped. No output is provided.
00594 
00595     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
00596   if no more input was provided, Z_DATA_ERROR if no flush point has been found,
00597   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
00598   case, the application may save the current current value of total_in which
00599   indicates where valid compressed data was found. In the error case, the
00600   application may repeatedly call inflateSync, providing more input each time,
00601   until success or end of the input data.
00602 */
00603 
00604 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
00605 /*
00606      This function is equivalent to inflateEnd followed by inflateInit,
00607    but does not free and reallocate all the internal decompression state.
00608    The stream will keep attributes that may have been set by inflateInit2.
00609 
00610       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
00611    stream state was inconsistent (such as zalloc or state being NULL).
00612 */
00613 
00614 
00615                         /* utility functions */
00616 
00617 /*
00618      The following utility functions are implemented on top of the
00619    basic stream-oriented functions. To simplify the interface, some
00620    default options are assumed (compression level and memory usage,
00621    standard memory allocation functions). The source code of these
00622    utility functions can easily be modified if you need special options.
00623 */
00624 
00625 ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
00626                                  const Bytef *source, uLong sourceLen));
00627 /*
00628      Compresses the source buffer into the destination buffer.  sourceLen is
00629    the byte length of the source buffer. Upon entry, destLen is the total
00630    size of the destination buffer, which must be at least 0.1% larger than
00631    sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
00632    compressed buffer.
00633      This function can be used to compress a whole file at once if the
00634    input file is mmap'ed.
00635      compress returns Z_OK if success, Z_MEM_ERROR if there was not
00636    enough memory, Z_BUF_ERROR if there was not enough room in the output
00637    buffer.
00638 */
00639 
00640 ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
00641                                   const Bytef *source, uLong sourceLen,
00642                                   int level));
00643 /*
00644      Compresses the source buffer into the destination buffer. The level
00645    parameter has the same meaning as in deflateInit.  sourceLen is the byte
00646    length of the source buffer. Upon entry, destLen is the total size of the
00647    destination buffer, which must be at least 0.1% larger than sourceLen plus
00648    12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
00649 
00650      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
00651    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
00652    Z_STREAM_ERROR if the level parameter is invalid.
00653 */
00654 
00655 ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
00656                                    const Bytef *source, uLong sourceLen));
00657 /*
00658      Decompresses the source buffer into the destination buffer.  sourceLen is
00659    the byte length of the source buffer. Upon entry, destLen is the total
00660    size of the destination buffer, which must be large enough to hold the
00661    entire uncompressed data. (The size of the uncompressed data must have
00662    been saved previously by the compressor and transmitted to the decompressor
00663    by some mechanism outside the scope of this compression library.)
00664    Upon exit, destLen is the actual size of the compressed buffer.
00665      This function can be used to decompress a whole file at once if the
00666    input file is mmap'ed.
00667 
00668      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
00669    enough memory, Z_BUF_ERROR if there was not enough room in the output
00670    buffer, or Z_DATA_ERROR if the input data was corrupted.
00671 */
00672 
00673 
00674 typedef voidp gzFile;
00675 
00676 ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
00677 /*
00678      Opens a gzip (.gz) file for reading or writing. The mode parameter
00679    is as in fopen ("rb" or "wb") but can also include a compression level
00680    ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
00681    Huffman only compression as in "wb1h". (See the description
00682    of deflateInit2 for more information about the strategy parameter.)
00683 
00684      gzopen can be used to read a file which is not in gzip format; in this
00685    case gzread will directly read from the file without decompression.
00686 
00687      gzopen returns NULL if the file could not be opened or if there was
00688    insufficient memory to allocate the (de)compression state; errno
00689    can be checked to distinguish the two cases (if errno is zero, the
00690    zlib error is Z_MEM_ERROR).  */
00691 
00692 ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
00693 /*
00694      gzdopen() associates a gzFile with the file descriptor fd.  File
00695    descriptors are obtained from calls like open, dup, creat, pipe or
00696    fileno (in the file has been previously opened with fopen).
00697    The mode parameter is as in gzopen.
00698      The next call of gzclose on the returned gzFile will also close the
00699    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
00700    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
00701      gzdopen returns NULL if there was insufficient memory to allocate
00702    the (de)compression state.
00703 */
00704 
00705 ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
00706 /*
00707      Dynamically update the compression level or strategy. See the description
00708    of deflateInit2 for the meaning of these parameters.
00709      gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
00710    opened for writing.
00711 */
00712 
00713 ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
00714 /*
00715      Reads the given number of uncompressed bytes from the compressed file.
00716    If the input file was not in gzip format, gzread copies the given number
00717    of bytes into the buffer.
00718      gzread returns the number of uncompressed bytes actually read (0 for
00719    end of file, -1 for error). */
00720 
00721 ZEXTERN int ZEXPORT    gzwrite OF((gzFile file, 
00722                                const voidp buf, unsigned len));
00723 /*
00724      Writes the given number of uncompressed bytes into the compressed file.
00725    gzwrite returns the number of uncompressed bytes actually written
00726    (0 in case of error).
00727 */
00728 
00729 ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
00730 /*
00731      Converts, formats, and writes the args to the compressed file under
00732    control of the format string, as in fprintf. gzprintf returns the number of
00733    uncompressed bytes actually written (0 in case of error).
00734 */
00735 
00736 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
00737 /*
00738       Writes the given null-terminated string to the compressed file, excluding
00739    the terminating null character.
00740       gzputs returns the number of characters written, or -1 in case of error.
00741 */
00742 
00743 ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
00744 /*
00745       Reads bytes from the compressed file until len-1 characters are read, or
00746    a newline character is read and transferred to buf, or an end-of-file
00747    condition is encountered.  The string is then terminated with a null
00748    character.
00749       gzgets returns buf, or Z_NULL in case of error.
00750 */
00751 
00752 ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
00753 /*
00754       Writes c, converted to an unsigned char, into the compressed file.
00755    gzputc returns the value that was written, or -1 in case of error.
00756 */
00757 
00758 ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
00759 /*
00760       Reads one byte from the compressed file. gzgetc returns this byte
00761    or -1 in case of end of file or error.
00762 */
00763 
00764 ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
00765 /*
00766      Flushes all pending output into the compressed file. The parameter
00767    flush is as in the deflate() function. The return value is the zlib
00768    error number (see function gzerror below). gzflush returns Z_OK if
00769    the flush parameter is Z_FINISH and all output could be flushed.
00770      gzflush should be called only when strictly necessary because it can
00771    degrade compression.
00772 */
00773 
00774 ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
00775                                   z_off_t offset, int whence));
00776 /* 
00777       Sets the starting position for the next gzread or gzwrite on the
00778    given compressed file. The offset represents a number of bytes in the
00779    uncompressed data stream. The whence parameter is defined as in lseek(2);
00780    the value SEEK_END is not supported.
00781      If the file is opened for reading, this function is emulated but can be
00782    extremely slow. If the file is opened for writing, only forward seeks are
00783    supported; gzseek then compresses a sequence of zeroes up to the new
00784    starting position.
00785 
00786       gzseek returns the resulting offset location as measured in bytes from
00787    the beginning of the uncompressed stream, or -1 in case of error, in
00788    particular if the file is opened for writing and the new starting position
00789    would be before the current position.
00790 */
00791 
00792 ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
00793 /*
00794      Rewinds the given file. This function is supported only for reading.
00795 
00796    gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
00797 */
00798 
00799 ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
00800 /*
00801      Returns the starting position for the next gzread or gzwrite on the
00802    given compressed file. This position represents a number of bytes in the
00803    uncompressed data stream.
00804 
00805    gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
00806 */
00807 
00808 ZEXTERN int ZEXPORT gzeof OF((gzFile file));
00809 /*
00810      Returns 1 when EOF has previously been detected reading the given
00811    input stream, otherwise zero.
00812 */
00813 
00814 ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
00815 /*
00816      Flushes all pending output if necessary, closes the compressed file
00817    and deallocates all the (de)compression state. The return value is the zlib
00818    error number (see function gzerror below).
00819 */
00820 
00821 ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
00822 /*
00823      Returns the error message for the last error which occurred on the
00824    given compressed file. errnum is set to zlib error number. If an
00825    error occurred in the file system and not in the compression library,
00826    errnum is set to Z_ERRNO and the application may consult errno
00827    to get the exact error code.
00828 */
00829 
00830                         /* checksum functions */
00831 
00832 /*
00833      These functions are not related to compression but are exported
00834    anyway because they might be useful in applications using the
00835    compression library.
00836 */
00837 
00838 ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
00839 
00840 /*
00841      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
00842    return the updated checksum. If buf is NULL, this function returns
00843    the required initial value for the checksum.
00844    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
00845    much faster. Usage example:
00846 
00847      uLong adler = adler32(0L, Z_NULL, 0);
00848 
00849      while (read_buffer(buffer, length) != EOF) {
00850        adler = adler32(adler, buffer, length);
00851      }
00852      if (adler != original_adler) error();
00853 */
00854 
00855 ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
00856 /*
00857      Update a running crc with the bytes buf[0..len-1] and return the updated
00858    crc. If buf is NULL, this function returns the required initial value
00859    for the crc. Pre- and post-conditioning (one's complement) is performed
00860    within this function so it shouldn't be done by the application.
00861    Usage example:
00862 
00863      uLong crc = crc32(0L, Z_NULL, 0);
00864 
00865      while (read_buffer(buffer, length) != EOF) {
00866        crc = crc32(crc, buffer, length);
00867      }
00868      if (crc != original_crc) error();
00869 */
00870 
00871 
00872                         /* various hacks, don't look :) */
00873 
00874 /* deflateInit and inflateInit are macros to allow checking the zlib version
00875  * and the compiler's view of z_stream:
00876  */
00877 ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
00878                                      const char *version, int stream_size));
00879 ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
00880                                      const char *version, int stream_size));
00881 ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
00882                                       int windowBits, int memLevel,
00883                                       int strategy, const char *version,
00884                                       int stream_size));
00885 ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
00886                                       const char *version, int stream_size));
00887 ZEXPORT int ZEXPORT inflateSave   OF((z_streamp strm, char **resultp));
00888 ZEXPORT int ZEXPORT inflateRestore OF((z_streamp strm, char *buf));
00889 
00890 #define deflateInit(strm, level) \
00891         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
00892 #define inflateInit(strm) \
00893         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
00894 #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
00895         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
00896                       (strategy),           ZLIB_VERSION, sizeof(z_stream))
00897 #define inflateInit2(strm, windowBits) \
00898         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
00899 
00900 
00901 #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
00902     struct internal_state {int dummy;}; /* hack for buggy compilers */
00903 #endif
00904 
00905 ZEXTERN const char   * ZEXPORT zError           OF((int err));
00906 ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
00907 ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
00908 
00909 #ifdef __cplusplus
00910 }
00911 #endif
00912 
00913 #endif /* _ZLIB_H */