Back to index

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