zlibdll.h

Go to the documentation of this file.
00001 /* zlibdll.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 
00031 /* Modifications:
00032  *     conversion to C++; to handle IStream objects; to be a DLL
00033  * Copyright (C) 1998 Autodesk, Inc.
00034  *
00035  * Written by Pete Samson, Kinetix
00036  */
00037 
00038 #pragma once
00039 
00040 #define ZLIB_VERSION "1.0.4"
00041 
00042 #include "maxheap.h"
00043 #include "strbasic.h"
00044 
00045 #define USE_ISTREAMS
00046 
00047 #define Z_NO_FLUSH      0
00048 #define Z_PARTIAL_FLUSH 1
00049 #define Z_SYNC_FLUSH    2
00050 #define Z_FULL_FLUSH    3
00051 #define Z_FINISH        4
00052 /* Allowed flush values; see deflate() below for details */
00053 
00054 #define Z_OK            0
00055 #define Z_STREAM_END    1
00056 #define Z_NEED_DICT     2
00057 #define Z_ERRNO        (-1)
00058 #define Z_STREAM_ERROR (-2)
00059 #define Z_DATA_ERROR   (-3)
00060 #define Z_MEM_ERROR    (-4)
00061 #define Z_BUF_ERROR    (-5)
00062 #define Z_VERSION_ERROR (-6)
00063 /* Return codes for the compression/decompression functions. Negative
00064  * values are errors, positive values are used for special but normal events.
00065  */
00066 
00067 
00068 #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
00069 
00070 #define Z_NO_COMPRESSION         0
00071 #define Z_BEST_SPEED             1
00072 #define Z_BEST_COMPRESSION       9
00073 #define Z_DEFAULT_COMPRESSION  (-1)
00074 /* compression levels */
00075 
00076 #define Z_FILTERED            1
00077 #define Z_HUFFMAN_ONLY        2
00078 #define Z_DEFAULT_STRATEGY    0
00079 /* compression strategy; see deflateInit2() below for details */
00080 
00081 
00082 // IMPORTANT: Must follow the definitions from zconf.h!
00083 typedef unsigned char  Byte;  /* 8 bits */
00084 typedef unsigned int   uInt;  /* 16 bits or more */
00085 
00086 // SR NOTE64: Support for files bigger than 4G; the code is reasonably clean and
00087 // can handle it without any problems.
00088 #if defined(_WIN64)
00089 #  include <basetsd.h>        // ULONG_PTR
00090 
00091 typedef ULONG_PTR uLong;      /* 32 bits or more */ 
00092 
00093 #else
00094 
00095 typedef unsigned long  uLong; /* 32 bits or more */
00096 
00097 #endif
00098 
00099 typedef unsigned long uLong32;   /* 32 bits always */
00100 
00101 typedef void     *voidpf;
00102 typedef void     *voidp;
00103 typedef voidpf (*alloc_func) (voidpf opaque, uInt items, uInt size);
00104 typedef void   (*free_func)  (voidpf opaque, voidpf address);
00105 typedef Byte  Bytef;
00106 typedef char   charf;
00107 typedef int    intf;
00108 typedef uInt   uIntf;
00109 typedef uLong  uLongf;
00110 typedef uLong32 uLong32f;
00111 
00112 typedef struct z_stream_s: public MaxHeapOperators {
00113     Bytef    *next_in;  /* next input byte */
00114     uInt     avail_in;  /* number of bytes available at next_in */
00115     uLong    total_in;  /* total nb of input bytes read so far */
00116 
00117     Bytef    *next_out; /* next output byte should be put there */
00118     uInt     avail_out; /* remaining free space at next_out */
00119     uLong    total_out; /* total nb of bytes output so far */
00120 
00121     char     *msg;      /* last error message, NULL if no error */
00122     struct internal_state *state; /* not visible by applications */
00123 
00124     alloc_func zalloc;  /* used to allocate the internal state */
00125     free_func  zfree;   /* used to free the internal state */
00126     voidpf     opaque;  /* private data object passed to zalloc and zfree */
00127 
00128     int     data_type;  /* best guess about the data type: ascii or binary */
00129     uLong   adler;      /* adler32 value of the uncompressed data */
00130     uLong   reserved;   /* reserved for future use */
00131 } z_stream;
00132 
00133 typedef z_stream *z_streamp;
00134 
00135 typedef mwchar_t WCHAR;
00136 
00137 
00138                         /* basic functions */
00139 
00140 extern const char *  zlibVersion(void);
00141 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
00142    If the first character differs, the library code actually used is
00143    not compatible with the zlib.h header file used by the application.
00144    This check is automatically made by deflateInit and inflateInit.
00145  */
00146 
00147 /* 
00148 extern int  deflateInit(z_streamp strm, int level);
00149 
00150      Initializes the internal stream state for compression. The fields
00151    zalloc, zfree and opaque must be initialized before by the caller.
00152    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
00153    use default allocation functions.
00154 
00155      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
00156    1 gives best speed, 9 gives best compression, 0 gives no compression at
00157    all (the input data is simply copied a block at a time).
00158    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
00159    compression (currently equivalent to level 6).
00160 
00161      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
00162    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
00163    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
00164    with the version assumed by the caller (ZLIB_VERSION).
00165    msg is set to null if there is no error message.  deflateInit does not
00166    perform any compression: this will be done by deflate().
00167 */
00168 
00169 
00170 extern int  deflate(z_streamp strm, int flush);
00171 /*
00172   Performs one or both of the following actions:
00173 
00174   - Compress more input starting at next_in and update next_in and avail_in
00175     accordingly. If not all input can be processed (because there is not
00176     enough room in the output buffer), next_in and avail_in are updated and
00177     processing will resume at this point for the next call of deflate().
00178 
00179   - Provide more output starting at next_out and update next_out and avail_out
00180     accordingly. This action is forced if the parameter flush is non zero.
00181     Forcing flush frequently degrades the compression ratio, so this parameter
00182     should be set only when necessary (in interactive applications).
00183     Some output may be provided even if flush is not set.
00184 
00185   Before the call of deflate(), the application should ensure that at least
00186   one of the actions is possible, by providing more input and/or consuming
00187   more output, and updating avail_in or avail_out accordingly; avail_out
00188   should never be zero before the call. The application can consume the
00189   compressed output when it wants, for example when the output buffer is full
00190   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
00191   and with zero avail_out, it must be called again after making room in the
00192   output buffer because there might be more output pending.
00193 
00194     If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
00195   block is terminated and flushed to the output buffer so that the
00196   decompressor can get all input data available so far. For method 9, a future
00197   variant on method 8, the current block will be flushed but not terminated.
00198   Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
00199   output is byte aligned (the compressor can clear its internal bit buffer)
00200   and the current block is always terminated; this can be useful if the
00201   compressor has to be restarted from scratch after an interruption (in which
00202   case the internal state of the compressor may be lost).
00203     If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
00204   special marker is output and the compression dictionary is discarded; this
00205   is useful to allow the decompressor to synchronize if one compressed block
00206   has been damaged (see inflateSync below).  Flushing degrades compression and
00207   so should be used only when necessary.  Using Z_FULL_FLUSH too often can
00208   seriously degrade the compression. If deflate returns with avail_out == 0,
00209   this function must be called again with the same value of the flush
00210   parameter and more output space (updated avail_out), until the flush is
00211   complete (deflate returns with non-zero avail_out).
00212 
00213     If the parameter flush is set to Z_FINISH, pending input is processed,
00214   pending output is flushed and deflate returns with Z_STREAM_END if there
00215   was enough output space; if deflate returns with Z_OK, this function must be
00216   called again with Z_FINISH and more output space (updated avail_out) but no
00217   more input data, until it returns with Z_STREAM_END or an error. After
00218   deflate has returned Z_STREAM_END, the only possible operations on the
00219   stream are deflateReset or deflateEnd.
00220   
00221     Z_FINISH can be used immediately after deflateInit if all the compression
00222   is to be done in a single step. In this case, avail_out must be at least
00223   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
00224   Z_STREAM_END, then it must be called again as described above.
00225 
00226     deflate() may update data_type if it can make a good guess about
00227   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
00228   binary. This field is only for information purposes and does not affect
00229   the compression algorithm in any manner.
00230 
00231     deflate() returns Z_OK if some progress has been made (more input
00232   processed or more output produced), Z_STREAM_END if all input has been
00233   consumed and all output has been produced (only when flush is set to
00234   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
00235   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
00236 */
00237 
00238 
00239 extern int  deflateEnd(z_streamp strm);
00240 /*
00241      All dynamically allocated data structures for this stream are freed.
00242    This function discards any unprocessed input and does not flush any
00243    pending output.
00244 
00245      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
00246    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
00247    prematurely (some input or output was discarded). In the error case,
00248    msg may be set but then points to a static string (which must not be
00249    deallocated).
00250 */
00251 
00252 
00253  
00254 extern int  inflateInit(z_streamp strm);
00255 
00256 /*
00257      Initializes the internal stream state for decompression. The fields
00258    zalloc, zfree and opaque must be initialized before by the caller.  If
00259    zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
00260    allocation functions.
00261 
00262      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
00263    enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
00264    with the version assumed by the caller.  msg is set to null if there is no
00265    error message. inflateInit does not perform any decompression: this will be
00266    done by inflate().
00267 */
00268 
00269 
00270 extern int  inflate(z_streamp strm, int flush);
00271 /*
00272   Performs one or both of the following actions:
00273 
00274   - Decompress more input starting at next_in and update next_in and avail_in
00275     accordingly. If not all input can be processed (because there is not
00276     enough room in the output buffer), next_in is updated and processing
00277     will resume at this point for the next call of inflate().
00278 
00279   - Provide more output starting at next_out and update next_out and avail_out
00280     accordingly.  inflate() provides as much output as possible, until there
00281     is no more input data or no more space in the output buffer (see below
00282     about the flush parameter).
00283 
00284   Before the call of inflate(), the application should ensure that at least
00285   one of the actions is possible, by providing more input and/or consuming
00286   more output, and updating the next_* and avail_* values accordingly.
00287   The application can consume the uncompressed output when it wants, for
00288   example when the output buffer is full (avail_out == 0), or after each
00289   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
00290   must be called again after making room in the output buffer because there
00291   might be more output pending.
00292 
00293     If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
00294   output as possible to the output buffer. The flushing behavior of inflate is
00295   not specified for values of the flush parameter other than Z_PARTIAL_FLUSH
00296   and Z_FINISH, but the current implementation actually flushes as much output
00297   as possible anyway.
00298 
00299     inflate() should normally be called until it returns Z_STREAM_END or an
00300   error. However if all decompression is to be performed in a single step
00301   (a single call of inflate), the parameter flush should be set to
00302   Z_FINISH. In this case all pending input is processed and all pending
00303   output is flushed; avail_out must be large enough to hold all the
00304   uncompressed data. (The size of the uncompressed data may have been saved
00305   by the compressor for this purpose.) The next operation on this stream must
00306   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
00307   is never required, but can be used to inform inflate that a faster routine
00308   may be used for the single inflate() call.
00309 
00310     inflate() returns Z_OK if some progress has been made (more input
00311   processed or more output produced), Z_STREAM_END if the end of the
00312   compressed data has been reached and all uncompressed output has been
00313   produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
00314   inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
00315   Z_STREAM_ERROR if the stream structure was inconsistent (for example if
00316   next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
00317   Z_BUF_ERROR if no progress is possible or if there was not enough room in
00318   the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
00319   application may then call inflateSync to look for a good compression block.
00320   In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
00321   dictionary chosen by the compressor.
00322 */
00323 
00324 
00325 extern int  inflateEnd(z_streamp strm);
00326 /*
00327      All dynamically allocated data structures for this stream are freed.
00328    This function discards any unprocessed input and does not flush any
00329    pending output.
00330 
00331      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
00332    was inconsistent. In the error case, msg may be set but then points to a
00333    static string (which must not be deallocated).
00334 */
00335 
00336                         /* Advanced functions */
00337 
00338 /*
00339     The following functions are needed only in some special applications.
00340 */
00341 
00342 extern int  deflateInit2(z_streamp strm,
00343                                    int  level,
00344                                    int  method,
00345                                    int  windowBits,
00346                                    int  memLevel,
00347                                    int  strategy);
00348 
00349 /*
00350      This is another version of deflateInit with more compression options. The
00351    fields next_in, zalloc, zfree and opaque must be initialized before by
00352    the caller.
00353 
00354      The method parameter is the compression method. It must be Z_DEFLATED in
00355    this version of the library. (Method 9 will allow a 64K history buffer and
00356    partial block flushes.)
00357 
00358      The windowBits parameter is the base two logarithm of the window size
00359    (the size of the history buffer).  It should be in the range 8..15 for this
00360    version of the library (the value 16 will be allowed for method 9). Larger
00361    values of this parameter result in better compression at the expense of
00362    memory usage. The default value is 15 if deflateInit is used instead.
00363 
00364      The memLevel parameter specifies how much memory should be allocated
00365    for the internal compression state. memLevel=1 uses minimum memory but
00366    is slow and reduces compression ratio; memLevel=9 uses maximum memory
00367    for optimal speed. The default value is 8. See zconf.h for total memory
00368    usage as a function of windowBits and memLevel.
00369 
00370      The strategy parameter is used to tune the compression algorithm. Use the
00371    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
00372    filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
00373    string match).  Filtered data consists mostly of small values with a
00374    somewhat random distribution. In this case, the compression algorithm is
00375    tuned to compress them better. The effect of Z_FILTERED is to force more
00376    Huffman coding and less string matching; it is somewhat intermediate
00377    between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
00378    the compression ratio but not the correctness of the compressed output even
00379    if it is not set appropriately.
00380 
00381      If next_in is not null, the library will use this buffer to hold also
00382    some history information; the buffer must either hold the entire input
00383    data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
00384    is null, the library will allocate its own history buffer (and leave next_in
00385    null). next_out need not be provided here but must be provided by the
00386    application for the next call of deflate().
00387 
00388      If the history buffer is provided by the application, next_in must
00389    must never be changed by the application since the compressor maintains
00390    information inside this buffer from call to call; the application
00391    must provide more input only by increasing avail_in. next_in is always
00392    reset by the library in this case.
00393 
00394       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
00395    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
00396    an invalid method). msg is set to null if there is no error message.
00397    deflateInit2 does not perform any compression: this will be done by
00398    deflate(). 
00399 
00400                             
00401 extern int  deflateSetDictionary(z_streamp strm,
00402                                            const Bytef *dictionary,
00403                            uInt  dictLength);
00404 /*
00405      Initializes the compression dictionary (history buffer) from the given
00406    byte sequence without producing any compressed output. This function must
00407    be called immediately after deflateInit or deflateInit2, before any call
00408    of deflate. The compressor and decompressor must use exactly the same
00409    dictionary (see inflateSetDictionary).
00410      The dictionary should consist of strings (byte sequences) that are likely
00411    to be encountered later in the data to be compressed, with the most commonly
00412    used strings preferably put towards the end of the dictionary. Using a
00413    dictionary is most useful when the data to be compressed is short and
00414    can be predicted with good accuracy; the data can then be compressed better
00415    than with the default empty dictionary. In this version of the library,
00416    only the last 32K bytes of the dictionary are used.
00417      Upon return of this function, strm->adler is set to the Adler32 value
00418    of the dictionary; the decompressor may later use this value to determine
00419    which dictionary has been used by the compressor. (The Adler32 value
00420    applies to the whole dictionary even if only a subset of the dictionary is
00421    actually used by the compressor.)
00422 
00423      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
00424    parameter is invalid (such as NULL dictionary) or the stream state
00425    is inconsistent (for example if deflate has already been called for this
00426    stream). deflateSetDictionary does not perform any compression: this will
00427    be done by deflate(). 
00428 */
00429 
00430 
00431 extern int  deflateReset(z_streamp strm);
00432 /*
00433      This function is equivalent to deflateEnd followed by deflateInit,
00434    but does not free and reallocate all the internal compression state.
00435    The stream will keep the same compression level and any other attributes
00436    that may have been set by deflateInit2.
00437 
00438       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
00439    stream state was inconsistent (such as zalloc or state being NULL).
00440 */
00441 
00442 
00443 /*   
00444 extern int  inflateInit2(z_streamp strm,
00445                                    int  windowBits);
00446 
00447      This is another version of inflateInit with more compression options. The
00448    fields next_out, zalloc, zfree and opaque must be initialized before by
00449    the caller.
00450 
00451      The windowBits parameter is the base two logarithm of the maximum window
00452    size (the size of the history buffer).  It should be in the range 8..15 for
00453    this version of the library (the value 16 will be allowed soon). The
00454    default value is 15 if inflateInit is used instead. If a compressed stream
00455    with a larger window size is given as input, inflate() will return with
00456    the error code Z_DATA_ERROR instead of trying to allocate a larger window.
00457 
00458      If next_out is not null, the library will use this buffer for the history
00459    buffer; the buffer must either be large enough to hold the entire output
00460    data, or have at least 1<<windowBits bytes.  If next_out is null, the
00461    library will allocate its own buffer (and leave next_out null). next_in
00462    need not be provided here but must be provided by the application for the
00463    next call of inflate().
00464 
00465      If the history buffer is provided by the application, next_out must
00466    never be changed by the application since the decompressor maintains
00467    history information inside this buffer from call to call; the application
00468    can only reset next_out to the beginning of the history buffer when
00469    avail_out is zero and all output has been consumed.
00470 
00471       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
00472    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
00473    windowBits < 8). msg is set to null if there is no error message.
00474    inflateInit2 does not perform any decompression: this will be done by
00475    inflate().
00476 */
00477 
00478 extern int  inflateSetDictionary(z_streamp strm,
00479                            const Bytef *dictionary,
00480                        uInt  dictLength);
00481 /*
00482      Initializes the decompression dictionary (history buffer) from the given
00483    uncompressed byte sequence. This function must be called immediately after
00484    a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
00485    by the compressor can be determined from the Adler32 value returned by this
00486    call of inflate. The compressor and decompressor must use exactly the same
00487    dictionary (see deflateSetDictionary).
00488 
00489      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
00490    parameter is invalid (such as NULL dictionary) or the stream state is
00491    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
00492    expected one (incorrect Adler32 value). inflateSetDictionary does not
00493    perform any decompression: this will be done by subsequent calls of
00494    inflate().
00495 */
00496 
00497 extern int  inflateSync(z_streamp strm);
00498 /* 
00499     Skips invalid compressed data until the special marker (see deflate()
00500   above) can be found, or until all available input is skipped. No output
00501   is provided.
00502 
00503     inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
00504   if no more input was provided, Z_DATA_ERROR if no marker has been found,
00505   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
00506   case, the application may save the current current value of total_in which
00507   indicates where valid compressed data was found. In the error case, the
00508   application may repeatedly call inflateSync, providing more input each time,
00509   until success or end of the input data.
00510 */
00511 
00512 
00513 extern int  inflateReset(z_streamp strm);
00514 /*
00515      This function is equivalent to inflateEnd followed by inflateInit,
00516    but does not free and reallocate all the internal decompression state.
00517    The stream will keep attributes that may have been set by inflateInit2.
00518 
00519       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
00520    stream state was inconsistent (such as zalloc or state being NULL).
00521 */
00522 
00523 
00524 
00525                         /* utility functions */
00526 
00527 /*
00528      The following utility functions are implemented on top of the
00529    basic stream-oriented functions. To simplify the interface, some
00530    default options are assumed (compression level, window size,
00531    standard memory allocation functions). The source code of these
00532    utility functions can easily be modified if you need special options.
00533 */
00534 
00535 extern int  compress(Bytef *dest,   uLongf *destLen,
00536                    const Bytef *source, uLong sourceLen);
00537 /*
00538      Compresses the source buffer into the destination buffer.  sourceLen is
00539    the byte length of the source buffer. Upon entry, destLen is the total
00540    size of the destination buffer, which must be at least 0.1% larger than
00541    sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
00542    compressed buffer.
00543      This function can be used to compress a whole file at once if the
00544    input file is mmap'ed.
00545      compress returns Z_OK if success, Z_MEM_ERROR if there was not
00546    enough memory, Z_BUF_ERROR if there was not enough room in the output
00547    buffer.
00548 */
00549 
00550 extern int  uncompress(Bytef *dest,   uLongf *destLen,
00551                  const Bytef *source, uLong sourceLen);
00552 /*
00553      Decompresses the source buffer into the destination buffer.  sourceLen is
00554    the byte length of the source buffer. Upon entry, destLen is the total
00555    size of the destination buffer, which must be large enough to hold the
00556    entire uncompressed data. (The size of the uncompressed data must have
00557    been saved previously by the compressor and transmitted to the decompressor
00558    by some mechanism outside the scope of this compression library.)
00559    Upon exit, destLen is the actual size of the compressed buffer.
00560      This function can be used to decompress a whole file at once if the
00561    input file is mmap'ed.
00562 
00563      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
00564    enough memory, Z_BUF_ERROR if there was not enough room in the output
00565    buffer, or Z_DATA_ERROR if the input data was corrupted.
00566 */
00567 
00568 typedef void     *voidp;
00569 typedef voidp gzFile;
00570 
00571 struct IStorage;
00572 struct IStream;
00573 
00574 #ifdef USE_ISTREAMS
00575 extern gzFile  gzopen(IStream *, const WCHAR *ipath, const char *path, const char *mode);
00576 #else
00577 extern gzFile  gzopen(const char *path, const char *mode);
00578 #endif
00579 /*
00580      Opens a gzip (.gz) file for reading or writing. The mode parameter
00581    is as in fopen ("rb" or "wb") but can also include a compression level
00582    ("wb9").  gzopen can be used to read a file which is not in gzip format;
00583    in this case gzread will directly read from the file without decompression.
00584      gzopen returns NULL if the file could not be opened or if there was
00585    insufficient memory to allocate the (de)compression state; errno
00586    can be checked to distinguish the two cases (if errno is zero, the
00587    zlib error is Z_MEM_ERROR).
00588 */
00589 
00590 
00591 extern int     gzread(gzFile file, voidp buf, unsigned len);
00592 /*
00593      Reads the given number of uncompressed bytes from the compressed file.
00594    If the input file was not in gzip format, gzread copies the given number
00595    of bytes into the buffer.
00596      gzread returns the number of uncompressed bytes actually read (0 for
00597    end of file, -1 for error). */
00598 
00599 extern int     gzwrite(gzFile file, const voidp buf, unsigned len);
00600 /*
00601      Writes the given number of uncompressed bytes into the compressed file.
00602    gzwrite returns the number of uncompressed bytes actually written
00603    (0 in case of error).
00604 */
00605 
00606 extern int     gzflush(gzFile file, int flush);
00607 /*
00608      Flushes all pending output into the compressed file. The parameter
00609    flush is as in the deflate() function. The return value is the zlib
00610    error number (see function gzerror below). gzflush returns Z_OK if
00611    the flush parameter is Z_FINISH and all output could be flushed.
00612      gzflush should be called only when strictly necessary because it can
00613    degrade compression.
00614 */
00615 
00616 extern int     gzclose(gzFile file);
00617 /*
00618      Flushes all pending output if necessary, closes the compressed file
00619    and deallocates all the (de)compression state. The return value is the zlib
00620    error number (see function gzerror below).
00621 */
00622 
00623 extern const char *  gzerror(gzFile file, int *errnum);
00624 /*
00625      Returns the error message for the last error which occurred on the
00626    given compressed file. errnum is set to zlib error number. If an
00627    error occurred in the file system and not in the compression library,
00628    errnum is set to Z_ERRNO and the application may consult errno
00629    to get the exact error code.
00630 */
00631 
00632                         /* checksum functions */
00633 extern uLong32 crc32   (uLong32 crc, const Bytef *buf, uInt len);
00634 /*
00635      Update a running crc with the bytes buf[0..len-1] and return the updated
00636    crc. If buf is NULL, this function returns the required initial value
00637    for the crc. Pre- and post-conditioning (one's complement) is performed
00638    within this function so it shouldn't be done by the application.
00639    Usage example:
00640 
00641      uLong crc = crc32(0L, Z_NULL, 0);
00642 
00643      while (read_buffer(buffer, length) != EOF) {
00644        crc = crc32(crc, buffer, length);
00645      }
00646      if (crc != original_crc) error();
00647 */
00648 
00649 
00650                         /* various hacks, don't look :) */
00651 
00652 /* deflateInit and inflateInit are macros to allow checking the zlib version
00653  * and the compiler's view of z_stream:
00654  */
00655 extern int  deflateInit_(z_streamp strm, int level,
00656                        const char *version, int stream_size);
00657 extern int  inflateInit_(z_streamp strm,
00658                    const char *version, int stream_size);
00659 extern int  deflateInit2_(z_streamp strm, int  level, int  method,
00660                     int windowBits, int memLevel, int strategy,
00661                     const char *version, int stream_size);
00662 extern int  inflateInit2_(z_streamp strm, int  windowBits,
00663                     const char *version, int stream_size);
00664 #define deflateInit(strm, level) \
00665         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
00666 #define inflateInit(strm) \
00667         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
00668 #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
00669         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
00670               (strategy),           ZLIB_VERSION, sizeof(z_stream))
00671 #define inflateInit2(strm, windowBits) \
00672         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
00673 
00674