home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / zlib / src / zlib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  39.3 KB  |  893 lines

  1. /* zlib.h -- interface of the 'zlib' general purpose compression library
  2.   version 1.0.4, Jul 24th, 1996.
  3.  
  4.   Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
  5.  
  6.   This software is provided 'as-is', without any express or implied
  7.   warranty.  In no event will the authors be held liable for any damages
  8.   arising from the use of this software.
  9.  
  10.   Permission is granted to anyone to use this software for any purpose,
  11.   including commercial applications, and to alter it and redistribute it
  12.   freely, subject to the following restrictions:
  13.  
  14.   1. The origin of this software must not be misrepresented; you must not
  15.      claim that you wrote the original software. If you use this software
  16.      in a product, an acknowledgment in the product documentation would be
  17.      appreciated but is not required.
  18.   2. Altered source versions must be plainly marked as such, and must not be
  19.      misrepresented as being the original software.
  20.   3. This notice may not be removed or altered from any source distribution.
  21.  
  22.   Jean-loup Gailly        Mark Adler
  23.   gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
  24.  
  25.  
  26.   The data format used by the zlib library is described by RFCs (Request for
  27.   Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
  28.   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  29. */
  30. /* This file was modified since it was taken from the zlib distribution */
  31.  
  32. #ifndef _ZLIB_H
  33. #define _ZLIB_H
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #include "zconf.h"
  40.  
  41. #define ZLIB_VERSION "1.0.4"
  42.  
  43. /* 
  44.      The 'zlib' compression library provides in-memory compression and
  45.   decompression functions, including integrity checks of the uncompressed
  46.   data.  This version of the library supports only one compression method
  47.   (deflation) but other algorithms may be added later and will have the same
  48.   stream interface.
  49.  
  50.      For compression the application must provide the output buffer and
  51.   may optionally provide the input buffer for optimization. For decompression,
  52.   the application must provide the input buffer and may optionally provide
  53.   the output buffer for optimization.
  54.  
  55.      Compression can be done in a single step if the buffers are large
  56.   enough (for example if an input file is mmap'ed), or can be done by
  57.   repeated calls of the compression function.  In the latter case, the
  58.   application must provide more input and/or consume the output
  59.   (providing more output space) before each call.
  60.  
  61.      The library does not install any signal handler. It is recommended to
  62.   add at least a handler for SIGSEGV when decompressing; the library checks
  63.   the consistency of the input data whenever possible but may go nuts
  64.   for some forms of corrupted input.
  65. */
  66.  
  67. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  68. typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
  69.  
  70. struct internal_state;
  71.  
  72. typedef struct z_stream_s {
  73.     Bytef    *next_in;  /* next input byte */
  74.     uInt     avail_in;  /* number of bytes available at next_in */
  75.     uLong    total_in;  /* total nb of input bytes read so far */
  76.  
  77.     Bytef    *next_out; /* next output byte should be put there */
  78.     uInt     avail_out; /* remaining free space at next_out */
  79.     uLong    total_out; /* total nb of bytes output so far */
  80.  
  81.     char     *msg;      /* last error message, NULL if no error */
  82.     struct internal_state FAR *state; /* not visible by applications */
  83.  
  84.     alloc_func zalloc;  /* used to allocate the internal state */
  85.     free_func  zfree;   /* used to free the internal state */
  86.     voidpf     opaque;  /* private data object passed to zalloc and zfree */
  87.  
  88.     int     data_type;  /* best guess about the data type: ascii or binary */
  89.     uLong   adler;      /* adler32 value of the uncompressed data */
  90.     uLong   reserved;   /* reserved for future use */
  91. } z_stream;
  92.  
  93. typedef z_stream FAR *z_streamp;
  94.  
  95. /*
  96.    The application must update next_in and avail_in when avail_in has
  97.    dropped to zero. It must update next_out and avail_out when avail_out
  98.    has dropped to zero. The application must initialize zalloc, zfree and
  99.    opaque before calling the init function. All other fields are set by the
  100.    compression library and must not be updated by the application.
  101.  
  102.    The opaque value provided by the application will be passed as the first
  103.    parameter for calls of zalloc and zfree. This can be useful for custom
  104.    memory management. The compression library attaches no meaning to the
  105.    opaque value.
  106.  
  107.    zalloc must return Z_NULL if there is not enough memory for the object.
  108.    On 16-bit systems, the functions zalloc and zfree must be able to allocate
  109.    exactly 65536 bytes, but will not be required to allocate more than this
  110.    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
  111.    pointers returned by zalloc for objects of exactly 65536 bytes *must*
  112.    have their offset normalized to zero. The default allocation function
  113.    provided by this library ensures this (see zutil.c). To reduce memory
  114.    requirements and avoid any allocation of 64K objects, at the expense of
  115.    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
  116.  
  117.    The fields total_in and total_out can be used for statistics or
  118.    progress reports. After compression, total_in holds the total size of
  119.    the uncompressed data and may be saved for use in the decompressor
  120.    (particularly if the decompressor wants to decompress everything in
  121.    a single step).
  122. */
  123.  
  124.                         /* constants */
  125.  
  126. #define Z_NO_FLUSH      0
  127. #define Z_PARTIAL_FLUSH 1
  128. #define Z_SYNC_FLUSH    2
  129. #define Z_FULL_FLUSH    3
  130. #define Z_FINISH        4
  131. /* Allowed flush values; see deflate() below for details */
  132.  
  133. #define Z_OK            0
  134. #define Z_STREAM_END    1
  135. #define Z_NEED_DICT     2
  136. #define Z_ERRNO        (-1)
  137. #define Z_STREAM_ERROR (-2)
  138. #define Z_DATA_ERROR   (-3)
  139. #define Z_MEM_ERROR    (-4)
  140. #define Z_BUF_ERROR    (-5)
  141. #define Z_VERSION_ERROR (-6)
  142. /* Return codes for the compression/decompression functions. Negative
  143.  * values are errors, positive values are used for special but normal events.
  144.  */
  145.  
  146. #define Z_NO_COMPRESSION         0
  147. #define Z_BEST_SPEED             1
  148. #define Z_BEST_COMPRESSION       9
  149. #define Z_DEFAULT_COMPRESSION  (-1)
  150. /* compression levels */
  151.  
  152. #define Z_FILTERED            1
  153. #define Z_HUFFMAN_ONLY        2
  154. #define Z_DEFAULT_STRATEGY    0
  155. /* compression strategy; see deflateInit2() below for details */
  156.  
  157. #define Z_BINARY   0
  158. #define Z_ASCII    1
  159. #define Z_UNKNOWN  2
  160. /* Possible values of the data_type field */
  161.  
  162. #define Z_DEFLATED   8
  163. /* The deflate compression method (the only one supported in this version) */
  164.  
  165. #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
  166.  
  167. #define zlib_version zlibVersion()
  168. /* for compatibility with versions < 1.0.2 */
  169.  
  170.                         /* basic functions */
  171.  
  172. #ifdef NETSCAPE
  173. PR_PUBLIC_API(extern const char *) zlibVersion (void);
  174. #else
  175. extern const char * EXPORT zlibVersion OF((void));
  176. #endif
  177. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
  178.    If the first character differs, the library code actually used is
  179.    not compatible with the zlib.h header file used by the application.
  180.    This check is automatically made by deflateInit and inflateInit.
  181.  */
  182.  
  183. /* 
  184. extern int EXPORT deflateInit OF((z_streamp strm, int level));
  185.  
  186.      Initializes the internal stream state for compression. The fields
  187.    zalloc, zfree and opaque must be initialized before by the caller.
  188.    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
  189.    use default allocation functions.
  190.  
  191.      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
  192.    1 gives best speed, 9 gives best compression, 0 gives no compression at
  193.    all (the input data is simply copied a block at a time).
  194.    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
  195.    compression (currently equivalent to level 6).
  196.  
  197.      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  198.    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
  199.    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
  200.    with the version assumed by the caller (ZLIB_VERSION).
  201.    msg is set to null if there is no error message.  deflateInit does not
  202.    perform any compression: this will be done by deflate().
  203. */
  204.  
  205.  
  206. #ifdef NETSCAPE
  207. PR_PUBLIC_API(extern int) deflate (z_streamp strm, int flush);
  208. #else
  209. extern int EXPORT deflate OF((z_streamp strm, int flush));
  210. #endif
  211. /*
  212.   Performs one or both of the following actions:
  213.  
  214.   - Compress more input starting at next_in and update next_in and avail_in
  215.     accordingly. If not all input can be processed (because there is not
  216.     enough room in the output buffer), next_in and avail_in are updated and
  217.     processing will resume at this point for the next call of deflate().
  218.  
  219.   - Provide more output starting at next_out and update next_out and avail_out
  220.     accordingly. This action is forced if the parameter flush is non zero.
  221.     Forcing flush frequently degrades the compression ratio, so this parameter
  222.     should be set only when necessary (in interactive applications).
  223.     Some output may be provided even if flush is not set.
  224.  
  225.   Before the call of deflate(), the application should ensure that at least
  226.   one of the actions is possible, by providing more input and/or consuming
  227.   more output, and updating avail_in or avail_out accordingly; avail_out
  228.   should never be zero before the call. The application can consume the
  229.   compressed output when it wants, for example when the output buffer is full
  230.   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
  231.   and with zero avail_out, it must be called again after making room in the
  232.   output buffer because there might be more output pending.
  233.  
  234.     If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
  235.   block is terminated and flushed to the output buffer so that the
  236.   decompressor can get all input data available so far. For method 9, a future
  237.   variant on method 8, the current block will be flushed but not terminated.
  238.   Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
  239.   output is byte aligned (the compressor can clear its internal bit buffer)
  240.   and the current block is always terminated; this can be useful if the
  241.   compressor has to be restarted from scratch after an interruption (in which
  242.   case the internal state of the compressor may be lost).
  243.     If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
  244.   special marker is output and the compression dictionary is discarded; this
  245.   is useful to allow the decompressor to synchronize if one compressed block
  246.   has been damaged (see inflateSync below).  Flushing degrades compression and
  247.   so should be used only when necessary.  Using Z_FULL_FLUSH too often can
  248.   seriously degrade the compression. If deflate returns with avail_out == 0,
  249.   this function must be called again with the same value of the flush
  250.   parameter and more output space (updated avail_out), until the flush is
  251.   complete (deflate returns with non-zero avail_out).
  252.  
  253.     If the parameter flush is set to Z_FINISH, pending input is processed,
  254.   pending output is flushed and deflate returns with Z_STREAM_END if there
  255.   was enough output space; if deflate returns with Z_OK, this function must be
  256.   called again with Z_FINISH and more output space (updated avail_out) but no
  257.   more input data, until it returns with Z_STREAM_END or an error. After
  258.   deflate has returned Z_STREAM_END, the only possible operations on the
  259.   stream are deflateReset or deflateEnd.
  260.   
  261.     Z_FINISH can be used immediately after deflateInit if all the compression
  262.   is to be done in a single step. In this case, avail_out must be at least
  263.   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
  264.   Z_STREAM_END, then it must be called again as described above.
  265.  
  266.     deflate() may update data_type if it can make a good guess about
  267.   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
  268.   binary. This field is only for information purposes and does not affect
  269.   the compression algorithm in any manner.
  270.  
  271.     deflate() returns Z_OK if some progress has been made (more input
  272.   processed or more output produced), Z_STREAM_END if all input has been
  273.   consumed and all output has been produced (only when flush is set to
  274.   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
  275.   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
  276. */
  277.  
  278.  
  279. #ifdef NETSCAPE
  280. PR_PUBLIC_API(extern int) deflateEnd (z_streamp strm);
  281. #else
  282. extern int EXPORT deflateEnd OF((z_streamp strm));
  283. #endif
  284. /*
  285.      All dynamically allocated data structures for this stream are freed.
  286.    This function discards any unprocessed input and does not flush any
  287.    pending output.
  288.  
  289.      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
  290.    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
  291.    prematurely (some input or output was discarded). In the error case,
  292.    msg may be set but then points to a static string (which must not be
  293.    deallocated).
  294. */
  295.  
  296.  
  297. /* 
  298. extern int EXPORT inflateInit OF((z_streamp strm));
  299.  
  300.      Initializes the internal stream state for decompression. The fields
  301.    zalloc, zfree and opaque must be initialized before by the caller.  If
  302.    zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
  303.    allocation functions.
  304.  
  305.      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  306.    enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
  307.    with the version assumed by the caller.  msg is set to null if there is no
  308.    error message. inflateInit does not perform any decompression: this will be
  309.    done by inflate().
  310. */
  311.  
  312.  
  313. #ifdef NETSCAPE
  314. PR_PUBLIC_API(extern int) inflate (z_streamp strm, int flush);
  315. #else
  316. extern int EXPORT inflate OF((z_streamp strm, int flush));
  317. #endif
  318. /*
  319.   Performs one or both of the following actions:
  320.  
  321.   - Decompress more input starting at next_in and update next_in and avail_in
  322.     accordingly. If not all input can be processed (because there is not
  323.     enough room in the output buffer), next_in is updated and processing
  324.     will resume at this point for the next call of inflate().
  325.  
  326.   - Provide more output starting at next_out and update next_out and avail_out
  327.     accordingly.  inflate() provides as much output as possible, until there
  328.     is no more input data or no more space in the output buffer (see below
  329.     about the flush parameter).
  330.  
  331.   Before the call of inflate(), the application should ensure that at least
  332.   one of the actions is possible, by providing more input and/or consuming
  333.   more output, and updating the next_* and avail_* values accordingly.
  334.   The application can consume the uncompressed output when it wants, for
  335.   example when the output buffer is full (avail_out == 0), or after each
  336.   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
  337.   must be called again after making room in the output buffer because there
  338.   might be more output pending.
  339.  
  340.     If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
  341.   output as possible to the output buffer. The flushing behavior of inflate is
  342.   not specified for values of the flush parameter other than Z_PARTIAL_FLUSH
  343.   and Z_FINISH, but the current implementation actually flushes as much output
  344.   as possible anyway.
  345.  
  346.     inflate() should normally be called until it returns Z_STREAM_END or an
  347.   error. However if all decompression is to be performed in a single step
  348.   (a single call of inflate), the parameter flush should be set to
  349.   Z_FINISH. In this case all pending input is processed and all pending
  350.   output is flushed; avail_out must be large enough to hold all the
  351.   uncompressed data. (The size of the uncompressed data may have been saved
  352.   by the compressor for this purpose.) The next operation on this stream must
  353.   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
  354.   is never required, but can be used to inform inflate that a faster routine
  355.   may be used for the single inflate() call.
  356.  
  357.     inflate() returns Z_OK if some progress has been made (more input
  358.   processed or more output produced), Z_STREAM_END if the end of the
  359.   compressed data has been reached and all uncompressed output has been
  360.   produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
  361.   inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
  362.   Z_STREAM_ERROR if the stream structure was inconsistent (for example if
  363.   next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
  364.   Z_BUF_ERROR if no progress is possible or if there was not enough room in
  365.   the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
  366.   application may then call inflateSync to look for a good compression block.
  367.   In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
  368.   dictionary chosen by the compressor.
  369. */
  370.  
  371.  
  372. #ifdef NETSCAPE
  373. PR_PUBLIC_API(extern int) inflateEnd (z_streamp strm);
  374. #else
  375. extern int EXPORT inflateEnd OF((z_streamp strm));
  376. #endif
  377. /*
  378.      All dynamically allocated data structures for this stream are freed.
  379.    This function discards any unprocessed input and does not flush any
  380.    pending output.
  381.  
  382.      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
  383.    was inconsistent. In the error case, msg may be set but then points to a
  384.    static string (which must not be deallocated).
  385. */
  386.  
  387.                         /* Advanced functions */
  388.  
  389. /*
  390.     The following functions are needed only in some special applications.
  391. */
  392.  
  393. /*   
  394. extern int EXPORT deflateInit2 OF((z_streamp strm,
  395.                                    int  level,
  396.                                    int  method,
  397.                                    int  windowBits,
  398.                                    int  memLevel,
  399.                                    int  strategy));
  400.  
  401.      This is another version of deflateInit with more compression options. The
  402.    fields next_in, zalloc, zfree and opaque must be initialized before by
  403.    the caller.
  404.  
  405.      The method parameter is the compression method. It must be Z_DEFLATED in
  406.    this version of the library. (Method 9 will allow a 64K history buffer and
  407.    partial block flushes.)
  408.  
  409.      The windowBits parameter is the base two logarithm of the window size
  410.    (the size of the history buffer).  It should be in the range 8..15 for this
  411.    version of the library (the value 16 will be allowed for method 9). Larger
  412.    values of this parameter result in better compression at the expense of
  413.    memory usage. The default value is 15 if deflateInit is used instead.
  414.  
  415.      The memLevel parameter specifies how much memory should be allocated
  416.    for the internal compression state. memLevel=1 uses minimum memory but
  417.    is slow and reduces compression ratio; memLevel=9 uses maximum memory
  418.    for optimal speed. The default value is 8. See zconf.h for total memory
  419.    usage as a function of windowBits and memLevel.
  420.  
  421.      The strategy parameter is used to tune the compression algorithm. Use the
  422.    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
  423.    filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
  424.    string match).  Filtered data consists mostly of small values with a
  425.    somewhat random distribution. In this case, the compression algorithm is
  426.    tuned to compress them better. The effect of Z_FILTERED is to force more
  427.    Huffman coding and less string matching; it is somewhat intermediate
  428.    between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
  429.    the compression ratio but not the correctness of the compressed output even
  430.    if it is not set appropriately.
  431.  
  432.      If next_in is not null, the library will use this buffer to hold also
  433.    some history information; the buffer must either hold the entire input
  434.    data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
  435.    is null, the library will allocate its own history buffer (and leave next_in
  436.    null). next_out need not be provided here but must be provided by the
  437.    application for the next call of deflate().
  438.  
  439.      If the history buffer is provided by the application, next_in must
  440.    must never be changed by the application since the compressor maintains
  441.    information inside this buffer from call to call; the application
  442.    must provide more input only by increasing avail_in. next_in is always
  443.    reset by the library in this case.
  444.  
  445.       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
  446.    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
  447.    an invalid method). msg is set to null if there is no error message.
  448.    deflateInit2 does not perform any compression: this will be done by
  449.    deflate(). 
  450. */
  451.                             
  452. #ifdef NETSCAPE
  453. PR_PUBLIC_API(extern int) deflateSetDictionary (z_streamp strm,
  454.                                            const Bytef *dictionary,
  455.                            uInt  dictLength);
  456. #else
  457. extern int EXPORT deflateSetDictionary OF((z_streamp strm,
  458.                                            const Bytef *dictionary,
  459.                            uInt  dictLength));
  460. #endif
  461. /*
  462.      Initializes the compression dictionary (history buffer) from the given
  463.    byte sequence without producing any compressed output. This function must
  464.    be called immediately after deflateInit or deflateInit2, before any call
  465.    of deflate. The compressor and decompressor must use exactly the same
  466.    dictionary (see inflateSetDictionary).
  467.      The dictionary should consist of strings (byte sequences) that are likely
  468.    to be encountered later in the data to be compressed, with the most commonly
  469.    used strings preferably put towards the end of the dictionary. Using a
  470.    dictionary is most useful when the data to be compressed is short and
  471.    can be predicted with good accuracy; the data can then be compressed better
  472.    than with the default empty dictionary. In this version of the library,
  473.    only the last 32K bytes of the dictionary are used.
  474.      Upon return of this function, strm->adler is set to the Adler32 value
  475.    of the dictionary; the decompressor may later use this value to determine
  476.    which dictionary has been used by the compressor. (The Adler32 value
  477.    applies to the whole dictionary even if only a subset of the dictionary is
  478.    actually used by the compressor.)
  479.  
  480.      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
  481.    parameter is invalid (such as NULL dictionary) or the stream state
  482.    is inconsistent (for example if deflate has already been called for this
  483.    stream). deflateSetDictionary does not perform any compression: this will
  484.    be done by deflate(). 
  485. */
  486.  
  487. #ifdef NETSCAPE
  488. PR_PUBLIC_API(extern int) deflateCopy (z_streamp dest, z_streamp source);
  489. #else
  490. extern int EXPORT deflateCopy OF((z_streamp dest, z_streamp source));
  491. #endif
  492. /*
  493.      Sets the destination stream as a complete copy of the source stream.  If
  494.    the source stream is using an application-supplied history buffer, a new
  495.    buffer is allocated for the destination stream.  The compressed output
  496.    buffer is always application-supplied. It's the responsibility of the
  497.    application to provide the correct values of next_out and avail_out for the
  498.    next call of deflate.
  499.  
  500.      This function can be useful when several compression strategies will be
  501.    tried, for example when there are several ways of pre-processing the input
  502.    data with a filter. The streams that will be discarded should then be freed
  503.    by calling deflateEnd.  Note that deflateCopy duplicates the internal
  504.    compression state which can be quite large, so this strategy is slow and
  505.    can consume lots of memory.
  506.  
  507.      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
  508.    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
  509.    (such as zalloc being NULL). msg is left unchanged in both source and
  510.    destination.
  511. */
  512.  
  513. #ifdef NETSCAPE
  514. PR_PUBLIC_API(extern int) deflateReset (z_streamp strm);
  515. #else
  516. extern int EXPORT deflateReset OF((z_streamp strm));
  517. #endif
  518. /*
  519.      This function is equivalent to deflateEnd followed by deflateInit,
  520.    but does not free and reallocate all the internal compression state.
  521.    The stream will keep the same compression level and any other attributes
  522.    that may have been set by deflateInit2.
  523.  
  524.       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  525.    stream state was inconsistent (such as zalloc or state being NULL).
  526. */
  527.  
  528. #ifdef NETSCAPE
  529. PR_PUBLIC_API(extern int) deflateParams (z_streamp strm, int level, int strategy);
  530. #else
  531. extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
  532. #endif
  533. /*
  534.      Dynamically update the compression level and compression strategy.
  535.    This can be used to switch between compression and straight copy of
  536.    the input data, or to switch to a different kind of input data requiring
  537.    a different strategy. If the compression level is changed, the input
  538.    available so far is compressed with the old level (and may be flushed);
  539.    the new level will take effect only at the next call of deflate().
  540.  
  541.      Before the call of deflateParams, the stream state must be set as for
  542.    a call of deflate(), since the currently available input may have to
  543.    be compressed and flushed. In particular, strm->avail_out must be non-zero.
  544.  
  545.      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
  546.    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
  547.    if strm->avail_out was zero.
  548. */
  549.  
  550. /*   
  551. extern int EXPORT inflateInit2 OF((z_streamp strm,
  552.                                    int  windowBits));
  553.  
  554.      This is another version of inflateInit with more compression options. The
  555.    fields next_out, zalloc, zfree and opaque must be initialized before by
  556.    the caller.
  557.  
  558.      The windowBits parameter is the base two logarithm of the maximum window
  559.    size (the size of the history buffer).  It should be in the range 8..15 for
  560.    this version of the library (the value 16 will be allowed soon). The
  561.    default value is 15 if inflateInit is used instead. If a compressed stream
  562.    with a larger window size is given as input, inflate() will return with
  563.    the error code Z_DATA_ERROR instead of trying to allocate a larger window.
  564.  
  565.      If next_out is not null, the library will use this buffer for the history
  566.    buffer; the buffer must either be large enough to hold the entire output
  567.    data, or have at least 1<<windowBits bytes.  If next_out is null, the
  568.    library will allocate its own buffer (and leave next_out null). next_in
  569.    need not be provided here but must be provided by the application for the
  570.    next call of inflate().
  571.  
  572.      If the history buffer is provided by the application, next_out must
  573.    never be changed by the application since the decompressor maintains
  574.    history information inside this buffer from call to call; the application
  575.    can only reset next_out to the beginning of the history buffer when
  576.    avail_out is zero and all output has been consumed.
  577.  
  578.       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
  579.    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
  580.    windowBits < 8). msg is set to null if there is no error message.
  581.    inflateInit2 does not perform any decompression: this will be done by
  582.    inflate().
  583. */
  584.  
  585. #ifdef NETSCAPE
  586. PR_PUBLIC_API(extern int) inflateSetDictionary (z_streamp strm,
  587.                            const Bytef *dictionary,
  588.                        uInt  dictLength);
  589. #else
  590. extern int EXPORT inflateSetDictionary OF((z_streamp strm,
  591.                            const Bytef *dictionary,
  592.                        uInt  dictLength));
  593. #endif
  594. /*
  595.      Initializes the decompression dictionary (history buffer) from the given
  596.    uncompressed byte sequence. This function must be called immediately after
  597.    a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
  598.    by the compressor can be determined from the Adler32 value returned by this
  599.    call of inflate. The compressor and decompressor must use exactly the same
  600.    dictionary (see deflateSetDictionary).
  601.  
  602.      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
  603.    parameter is invalid (such as NULL dictionary) or the stream state is
  604.    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
  605.    expected one (incorrect Adler32 value). inflateSetDictionary does not
  606.    perform any decompression: this will be done by subsequent calls of
  607.    inflate().
  608. */
  609.  
  610. #ifdef NETSCAPE
  611. PR_PUBLIC_API(extern int) inflateSync (z_streamp strm);
  612. #else
  613. extern int EXPORT inflateSync OF((z_streamp strm));
  614. #endif
  615. /* 
  616.     Skips invalid compressed data until the special marker (see deflate()
  617.   above) can be found, or until all available input is skipped. No output
  618.   is provided.
  619.  
  620.     inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
  621.   if no more input was provided, Z_DATA_ERROR if no marker has been found,
  622.   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
  623.   case, the application may save the current current value of total_in which
  624.   indicates where valid compressed data was found. In the error case, the
  625.   application may repeatedly call inflateSync, providing more input each time,
  626.   until success or end of the input data.
  627. */
  628.  
  629. #ifdef NETSCAPE
  630. PR_PUBLIC_API(extern int) inflateReset (z_streamp strm);
  631. #else
  632. extern int EXPORT inflateReset OF((z_streamp strm));
  633. #endif
  634. /*
  635.      This function is equivalent to inflateEnd followed by inflateInit,
  636.    but does not free and reallocate all the internal decompression state.
  637.    The stream will keep attributes that may have been set by inflateInit2.
  638.  
  639.       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  640.    stream state was inconsistent (such as zalloc or state being NULL).
  641. */
  642.  
  643.  
  644.                         /* utility functions */
  645.  
  646. /*
  647.      The following utility functions are implemented on top of the
  648.    basic stream-oriented functions. To simplify the interface, some
  649.    default options are assumed (compression level, window size,
  650.    standard memory allocation functions). The source code of these
  651.    utility functions can easily be modified if you need special options.
  652. */
  653.  
  654. #ifdef NETSCAPE
  655. PR_PUBLIC_API(extern int) compress (Bytef *dest,   uLongf *destLen,
  656.                    const Bytef *source, uLong sourceLen);
  657. #else
  658. extern int EXPORT compress OF((Bytef *dest,   uLongf *destLen,
  659.                    const Bytef *source, uLong sourceLen));
  660. #endif
  661. /*
  662.      Compresses the source buffer into the destination buffer.  sourceLen is
  663.    the byte length of the source buffer. Upon entry, destLen is the total
  664.    size of the destination buffer, which must be at least 0.1% larger than
  665.    sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
  666.    compressed buffer.
  667.      This function can be used to compress a whole file at once if the
  668.    input file is mmap'ed.
  669.      compress returns Z_OK if success, Z_MEM_ERROR if there was not
  670.    enough memory, Z_BUF_ERROR if there was not enough room in the output
  671.    buffer.
  672. */
  673.  
  674. #ifdef NETSCAPE
  675. PR_PUBLIC_API(extern int) uncompress (Bytef *dest,   uLongf *destLen,
  676.                  const Bytef *source, uLong sourceLen);
  677. #else
  678. extern int EXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
  679.                  const Bytef *source, uLong sourceLen));
  680. #endif
  681. /*
  682.      Decompresses the source buffer into the destination buffer.  sourceLen is
  683.    the byte length of the source buffer. Upon entry, destLen is the total
  684.    size of the destination buffer, which must be large enough to hold the
  685.    entire uncompressed data. (The size of the uncompressed data must have
  686.    been saved previously by the compressor and transmitted to the decompressor
  687.    by some mechanism outside the scope of this compression library.)
  688.    Upon exit, destLen is the actual size of the compressed buffer.
  689.      This function can be used to decompress a whole file at once if the
  690.    input file is mmap'ed.
  691.  
  692.      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
  693.    enough memory, Z_BUF_ERROR if there was not enough room in the output
  694.    buffer, or Z_DATA_ERROR if the input data was corrupted.
  695. */
  696.  
  697.  
  698. typedef voidp gzFile;
  699.  
  700. #ifdef NETSCAPE
  701. PR_PUBLIC_API(extern gzFile) gzopen  (const char *path, const char *mode);
  702. #else
  703. extern gzFile EXPORT gzopen  OF((const char *path, const char *mode));
  704. #endif
  705. /*
  706.      Opens a gzip (.gz) file for reading or writing. The mode parameter
  707.    is as in fopen ("rb" or "wb") but can also include a compression level
  708.    ("wb9").  gzopen can be used to read a file which is not in gzip format;
  709.    in this case gzread will directly read from the file without decompression.
  710.      gzopen returns NULL if the file could not be opened or if there was
  711.    insufficient memory to allocate the (de)compression state; errno
  712.    can be checked to distinguish the two cases (if errno is zero, the
  713.    zlib error is Z_MEM_ERROR).
  714. */
  715.  
  716. #ifdef NETSCAPE
  717. PR_PUBLIC_API(extern gzFile) gzdopen  (int fd, const char *mode);
  718. #else
  719. extern gzFile EXPORT gzdopen  OF((int fd, const char *mode));
  720. #endif
  721. /*
  722.      gzdopen() associates a gzFile with the file descriptor fd.  File
  723.    descriptors are obtained from calls like open, dup, creat, pipe or
  724.    fileno (in the file has been previously opened with fopen).
  725.    The mode parameter is as in gzopen.
  726.      The next call of gzclose on the returned gzFile will also close the
  727.    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
  728.    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
  729.      gzdopen returns NULL if there was insufficient memory to allocate
  730.    the (de)compression state.
  731. */
  732.  
  733. #ifdef NETSCAPE
  734. PR_PUBLIC_API(extern int)    gzread  (gzFile file, voidp buf, unsigned len);
  735. #else
  736. extern int EXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
  737. #endif
  738. /*
  739.      Reads the given number of uncompressed bytes from the compressed file.
  740.    If the input file was not in gzip format, gzread copies the given number
  741.    of bytes into the buffer.
  742.      gzread returns the number of uncompressed bytes actually read (0 for
  743.    end of file, -1 for error). */
  744.  
  745. #ifdef NETSCAPE
  746. PR_PUBLIC_API(extern int)    gzwrite (gzFile file, const voidp buf, unsigned len);
  747. #else
  748. extern int EXPORT    gzwrite OF((gzFile file, const voidp buf, unsigned len));
  749. #endif
  750. /*
  751.      Writes the given number of uncompressed bytes into the compressed file.
  752.    gzwrite returns the number of uncompressed bytes actually written
  753.    (0 in case of error).
  754. */
  755.  
  756. #ifdef NETSCAPE
  757. PR_PUBLIC_API(extern int)    gzflush (gzFile file, int flush);
  758. #else
  759. extern int EXPORT    gzflush OF((gzFile file, int flush));
  760. #endif
  761. /*
  762.      Flushes all pending output into the compressed file. The parameter
  763.    flush is as in the deflate() function. The return value is the zlib
  764.    error number (see function gzerror below). gzflush returns Z_OK if
  765.    the flush parameter is Z_FINISH and all output could be flushed.
  766.      gzflush should be called only when strictly necessary because it can
  767.    degrade compression.
  768. */
  769.  
  770. #ifdef NETSCAPE
  771. PR_PUBLIC_API(extern int)    gzclose (gzFile file);
  772. #else
  773. extern int EXPORT    gzclose OF((gzFile file));
  774. #endif
  775. /*
  776.      Flushes all pending output if necessary, closes the compressed file
  777.    and deallocates all the (de)compression state. The return value is the zlib
  778.    error number (see function gzerror below).
  779. */
  780.  
  781. #ifdef NETSCAPE
  782. PR_PUBLIC_API(extern const char *) gzerror (gzFile file, int *errnum);
  783. #else
  784. extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
  785. #endif
  786. /*
  787.      Returns the error message for the last error which occurred on the
  788.    given compressed file. errnum is set to zlib error number. If an
  789.    error occurred in the file system and not in the compression library,
  790.    errnum is set to Z_ERRNO and the application may consult errno
  791.    to get the exact error code.
  792. */
  793.  
  794.                         /* checksum functions */
  795.  
  796. /*
  797.      These functions are not related to compression but are exported
  798.    anyway because they might be useful in applications using the
  799.    compression library.
  800. */
  801.  
  802. #ifdef NETSCAPE
  803. PR_PUBLIC_API(extern uLong) adler32 (uLong adler, const Bytef *buf, uInt len);
  804. #else
  805. extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  806. #endif
  807.  
  808. /*
  809.      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
  810.    return the updated checksum. If buf is NULL, this function returns
  811.    the required initial value for the checksum.
  812.    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
  813.    much faster. Usage example:
  814.  
  815.      uLong adler = adler32(0L, Z_NULL, 0);
  816.  
  817.      while (read_buffer(buffer, length) != EOF) {
  818.        adler = adler32(adler, buffer, length);
  819.      }
  820.      if (adler != original_adler) error();
  821. */
  822.  
  823. #ifdef NETSCAPE
  824. PR_PUBLIC_API(extern uLong) crc32   (uLong crc, const Bytef *buf, uInt len);
  825. #else
  826. extern uLong EXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
  827. #endif
  828. /*
  829.      Update a running crc with the bytes buf[0..len-1] and return the updated
  830.    crc. If buf is NULL, this function returns the required initial value
  831.    for the crc. Pre- and post-conditioning (one's complement) is performed
  832.    within this function so it shouldn't be done by the application.
  833.    Usage example:
  834.  
  835.      uLong crc = crc32(0L, Z_NULL, 0);
  836.  
  837.      while (read_buffer(buffer, length) != EOF) {
  838.        crc = crc32(crc, buffer, length);
  839.      }
  840.      if (crc != original_crc) error();
  841. */
  842.  
  843.  
  844.                         /* various hacks, don't look :) */
  845.  
  846. /* deflateInit and inflateInit are macros to allow checking the zlib version
  847.  * and the compiler's view of z_stream:
  848.  */
  849. #ifdef NETSCAPE
  850. PR_PUBLIC_API(extern int) deflateInit_ (z_streamp strm, int level, const char *version, 
  851.                     int stream_size);
  852. PR_PUBLIC_API(extern int) inflateInit_ (z_streamp strm, const char *version, 
  853.                     int stream_size);
  854. PR_PUBLIC_API(extern int) deflateInit2_ (z_streamp strm, int  level, int  method, 
  855.                      int windowBits, int memLevel, int strategy, 
  856.                      const char *version, int stream_size);
  857. PR_PUBLIC_API(extern int) inflateInit2_ (z_streamp strm, int  windowBits, 
  858.                      const char *version, int stream_size);
  859. #else
  860. extern int EXPORT deflateInit_ OF((z_streamp strm, int level, const char *version, 
  861.                    int stream_size));
  862. extern int EXPORT inflateInit_ OF((z_streamp strm, const char *version, 
  863.                    int stream_size));
  864. extern int EXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method, 
  865.                     int windowBits, int memLevel, int strategy, 
  866.                     const char *version, int stream_size));
  867. extern int EXPORT inflateInit2_ OF((z_streamp strm, int  windowBits, 
  868.                     const char *version, int stream_size));
  869. #endif /* NETSCAPE */
  870.  
  871.  
  872. #define deflateInit(strm, level) \
  873.         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
  874. #define inflateInit(strm) \
  875.         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
  876. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  877.         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  878.               (strategy),           ZLIB_VERSION, sizeof(z_stream))
  879. #define inflateInit2(strm, windowBits) \
  880.         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  881.  
  882. #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
  883.     struct internal_state {int dummy;}; /* hack for buggy compilers */
  884. #endif
  885.  
  886. uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
  887.  
  888. #ifdef __cplusplus
  889. }
  890. #endif
  891.  
  892. #endif /* _ZLIB_H */
  893.