Home | History | Annotate | Line # | Download | only in net
zlib.h revision 1.2
      1  1.2  christos /*	$NetBSD: zlib.h,v 1.2 1997/03/12 20:27:11 christos Exp $	*/
      2  1.2  christos /*	Id: zlib.h,v 1.4 1997/03/04 03:26:36 paulus Exp 	*/
      3  1.1    paulus 
      4  1.1    paulus /*
      5  1.1    paulus  * This file is derived from zlib.h and zconf.h from the zlib-0.95
      6  1.1    paulus  * distribution by Jean-loup Gailly and Mark Adler, with some additions
      7  1.1    paulus  * by Paul Mackerras to aid in implementing Deflate compression and
      8  1.1    paulus  * decompression for PPP packets.
      9  1.1    paulus  */
     10  1.1    paulus 
     11  1.2  christos /*
     12  1.2  christos  *  ==FILEVERSION 960122==
     13  1.2  christos  *
     14  1.2  christos  * This marker is used by the Linux installation script to determine
     15  1.2  christos  * whether an up-to-date version of this file is already installed.
     16  1.2  christos  */
     17  1.2  christos 
     18  1.1    paulus /* zlib.h -- interface of the 'zlib' general purpose compression library
     19  1.1    paulus   version 0.95, Aug 16th, 1995.
     20  1.1    paulus 
     21  1.1    paulus   Copyright (C) 1995 Jean-loup Gailly and Mark Adler
     22  1.1    paulus 
     23  1.1    paulus   This software is provided 'as-is', without any express or implied
     24  1.1    paulus   warranty.  In no event will the authors be held liable for any damages
     25  1.1    paulus   arising from the use of this software.
     26  1.1    paulus 
     27  1.1    paulus   Permission is granted to anyone to use this software for any purpose,
     28  1.1    paulus   including commercial applications, and to alter it and redistribute it
     29  1.1    paulus   freely, subject to the following restrictions:
     30  1.1    paulus 
     31  1.1    paulus   1. The origin of this software must not be misrepresented; you must not
     32  1.1    paulus      claim that you wrote the original software. If you use this software
     33  1.1    paulus      in a product, an acknowledgment in the product documentation would be
     34  1.1    paulus      appreciated but is not required.
     35  1.1    paulus   2. Altered source versions must be plainly marked as such, and must not be
     36  1.1    paulus      misrepresented as being the original software.
     37  1.1    paulus   3. This notice may not be removed or altered from any source distribution.
     38  1.1    paulus 
     39  1.1    paulus   Jean-loup Gailly        Mark Adler
     40  1.1    paulus   gzip (at) prep.ai.mit.edu    madler (at) alumni.caltech.edu
     41  1.1    paulus  */
     42  1.1    paulus 
     43  1.1    paulus #ifndef _ZLIB_H
     44  1.1    paulus #define _ZLIB_H
     45  1.1    paulus 
     46  1.1    paulus /* #include "zconf.h" */	/* included directly here */
     47  1.1    paulus 
     48  1.1    paulus /* zconf.h -- configuration of the zlib compression library
     49  1.1    paulus  * Copyright (C) 1995 Jean-loup Gailly.
     50  1.1    paulus  * For conditions of distribution and use, see copyright notice in zlib.h
     51  1.1    paulus  */
     52  1.1    paulus 
     53  1.1    paulus /* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
     54  1.1    paulus 
     55  1.1    paulus /*
     56  1.1    paulus      The library does not install any signal handler. It is recommended to
     57  1.1    paulus   add at least a handler for SIGSEGV when decompressing; the library checks
     58  1.1    paulus   the consistency of the input data whenever possible but may go nuts
     59  1.1    paulus   for some forms of corrupted input.
     60  1.1    paulus  */
     61  1.1    paulus 
     62  1.1    paulus /*
     63  1.1    paulus  * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
     64  1.1    paulus  * than 64k bytes at a time (needed on systems with 16-bit int).
     65  1.1    paulus  * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
     66  1.1    paulus  * at addresses which are not a multiple of their size.
     67  1.1    paulus  * Under DOS, -DFAR=far or -DFAR=__far may be needed.
     68  1.1    paulus  */
     69  1.1    paulus 
     70  1.1    paulus #ifndef STDC
     71  1.1    paulus #  if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
     72  1.1    paulus #    define STDC
     73  1.1    paulus #  endif
     74  1.1    paulus #endif
     75  1.1    paulus 
     76  1.1    paulus #ifdef	__MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
     77  1.1    paulus #  include <unix.h>
     78  1.1    paulus #endif
     79  1.1    paulus 
     80  1.1    paulus /* Maximum value for memLevel in deflateInit2 */
     81  1.1    paulus #ifndef MAX_MEM_LEVEL
     82  1.1    paulus #  ifdef MAXSEG_64K
     83  1.1    paulus #    define MAX_MEM_LEVEL 8
     84  1.1    paulus #  else
     85  1.1    paulus #    define MAX_MEM_LEVEL 9
     86  1.1    paulus #  endif
     87  1.1    paulus #endif
     88  1.1    paulus 
     89  1.1    paulus #ifndef FAR
     90  1.1    paulus #  define FAR
     91  1.1    paulus #endif
     92  1.1    paulus 
     93  1.1    paulus /* Maximum value for windowBits in deflateInit2 and inflateInit2 */
     94  1.1    paulus #ifndef MAX_WBITS
     95  1.1    paulus #  define MAX_WBITS   15 /* 32K LZ77 window */
     96  1.1    paulus #endif
     97  1.1    paulus 
     98  1.1    paulus /* The memory requirements for deflate are (in bytes):
     99  1.1    paulus             1 << (windowBits+2)   +  1 << (memLevel+9)
    100  1.1    paulus  that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
    101  1.1    paulus  plus a few kilobytes for small objects. For example, if you want to reduce
    102  1.1    paulus  the default memory requirements from 256K to 128K, compile with
    103  1.1    paulus      make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
    104  1.1    paulus  Of course this will generally degrade compression (there's no free lunch).
    105  1.1    paulus 
    106  1.1    paulus    The memory requirements for inflate are (in bytes) 1 << windowBits
    107  1.1    paulus  that is, 32K for windowBits=15 (default value) plus a few kilobytes
    108  1.1    paulus  for small objects.
    109  1.1    paulus */
    110  1.1    paulus 
    111  1.1    paulus                         /* Type declarations */
    112  1.1    paulus 
    113  1.1    paulus #ifndef OF /* function prototypes */
    114  1.1    paulus #  ifdef STDC
    115  1.1    paulus #    define OF(args)  args
    116  1.1    paulus #  else
    117  1.1    paulus #    define OF(args)  ()
    118  1.1    paulus #  endif
    119  1.1    paulus #endif
    120  1.1    paulus 
    121  1.1    paulus typedef unsigned char  Byte;  /* 8 bits */
    122  1.1    paulus typedef unsigned int   uInt;  /* 16 bits or more */
    123  1.1    paulus typedef unsigned long  uLong; /* 32 bits or more */
    124  1.1    paulus 
    125  1.1    paulus typedef Byte FAR Bytef;
    126  1.1    paulus typedef char FAR charf;
    127  1.1    paulus typedef int FAR intf;
    128  1.1    paulus typedef uInt FAR uIntf;
    129  1.1    paulus typedef uLong FAR uLongf;
    130  1.1    paulus 
    131  1.1    paulus #ifdef STDC
    132  1.1    paulus    typedef void FAR *voidpf;
    133  1.1    paulus    typedef void     *voidp;
    134  1.1    paulus #else
    135  1.1    paulus    typedef Byte FAR *voidpf;
    136  1.1    paulus    typedef Byte     *voidp;
    137  1.1    paulus #endif
    138  1.1    paulus 
    139  1.1    paulus /* end of original zconf.h */
    140  1.1    paulus 
    141  1.1    paulus #define ZLIB_VERSION "0.95P"
    142  1.1    paulus 
    143  1.1    paulus /*
    144  1.1    paulus      The 'zlib' compression library provides in-memory compression and
    145  1.1    paulus   decompression functions, including integrity checks of the uncompressed
    146  1.1    paulus   data.  This version of the library supports only one compression method
    147  1.1    paulus   (deflation) but other algorithms may be added later and will have the same
    148  1.1    paulus   stream interface.
    149  1.1    paulus 
    150  1.1    paulus      For compression the application must provide the output buffer and
    151  1.1    paulus   may optionally provide the input buffer for optimization. For decompression,
    152  1.1    paulus   the application must provide the input buffer and may optionally provide
    153  1.1    paulus   the output buffer for optimization.
    154  1.1    paulus 
    155  1.1    paulus      Compression can be done in a single step if the buffers are large
    156  1.1    paulus   enough (for example if an input file is mmap'ed), or can be done by
    157  1.1    paulus   repeated calls of the compression function.  In the latter case, the
    158  1.1    paulus   application must provide more input and/or consume the output
    159  1.1    paulus   (providing more output space) before each call.
    160  1.1    paulus */
    161  1.1    paulus 
    162  1.1    paulus typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
    163  1.1    paulus typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt nbytes));
    164  1.1    paulus 
    165  1.1    paulus struct internal_state;
    166  1.1    paulus 
    167  1.1    paulus typedef struct z_stream_s {
    168  1.1    paulus     Bytef    *next_in;  /* next input byte */
    169  1.1    paulus     uInt     avail_in;  /* number of bytes available at next_in */
    170  1.1    paulus     uLong    total_in;  /* total nb of input bytes read so far */
    171  1.1    paulus 
    172  1.1    paulus     Bytef    *next_out; /* next output byte should be put there */
    173  1.1    paulus     uInt     avail_out; /* remaining free space at next_out */
    174  1.1    paulus     uLong    total_out; /* total nb of bytes output so far */
    175  1.1    paulus 
    176  1.1    paulus     char     *msg;      /* last error message, NULL if no error */
    177  1.1    paulus     struct internal_state FAR *state; /* not visible by applications */
    178  1.1    paulus 
    179  1.1    paulus     alloc_func zalloc;  /* used to allocate the internal state */
    180  1.1    paulus     free_func  zfree;   /* used to free the internal state */
    181  1.1    paulus     voidp      opaque;  /* private data object passed to zalloc and zfree */
    182  1.1    paulus 
    183  1.1    paulus     Byte     data_type; /* best guess about the data type: ascii or binary */
    184  1.1    paulus 
    185  1.1    paulus } z_stream;
    186  1.1    paulus 
    187  1.1    paulus /*
    188  1.1    paulus    The application must update next_in and avail_in when avail_in has
    189  1.1    paulus    dropped to zero. It must update next_out and avail_out when avail_out
    190  1.1    paulus    has dropped to zero. The application must initialize zalloc, zfree and
    191  1.1    paulus    opaque before calling the init function. All other fields are set by the
    192  1.1    paulus    compression library and must not be updated by the application.
    193  1.1    paulus 
    194  1.1    paulus    The opaque value provided by the application will be passed as the first
    195  1.1    paulus    parameter for calls of zalloc and zfree. This can be useful for custom
    196  1.1    paulus    memory management. The compression library attaches no meaning to the
    197  1.1    paulus    opaque value.
    198  1.1    paulus 
    199  1.1    paulus    zalloc must return Z_NULL if there is not enough memory for the object.
    200  1.1    paulus    On 16-bit systems, the functions zalloc and zfree must be able to allocate
    201  1.1    paulus    exactly 65536 bytes, but will not be required to allocate more than this
    202  1.1    paulus    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
    203  1.1    paulus    pointers returned by zalloc for objects of exactly 65536 bytes *must*
    204  1.1    paulus    have their offset normalized to zero. The default allocation function
    205  1.1    paulus    provided by this library ensures this (see zutil.c). To reduce memory
    206  1.1    paulus    requirements and avoid any allocation of 64K objects, at the expense of
    207  1.1    paulus    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
    208  1.1    paulus 
    209  1.1    paulus    The fields total_in and total_out can be used for statistics or
    210  1.1    paulus    progress reports. After compression, total_in holds the total size of
    211  1.1    paulus    the uncompressed data and may be saved for use in the decompressor
    212  1.1    paulus    (particularly if the decompressor wants to decompress everything in
    213  1.1    paulus    a single step).
    214  1.1    paulus */
    215  1.1    paulus 
    216  1.1    paulus                         /* constants */
    217  1.1    paulus 
    218  1.1    paulus #define Z_NO_FLUSH      0
    219  1.1    paulus #define Z_PARTIAL_FLUSH 1
    220  1.1    paulus #define Z_FULL_FLUSH    2
    221  1.1    paulus #define Z_SYNC_FLUSH    3 /* experimental: partial_flush + byte align */
    222  1.1    paulus #define Z_FINISH        4
    223  1.1    paulus #define Z_PACKET_FLUSH	5
    224  1.1    paulus /* See deflate() below for the usage of these constants */
    225  1.1    paulus 
    226  1.1    paulus #define Z_OK            0
    227  1.1    paulus #define Z_STREAM_END    1
    228  1.1    paulus #define Z_ERRNO        (-1)
    229  1.1    paulus #define Z_STREAM_ERROR (-2)
    230  1.1    paulus #define Z_DATA_ERROR   (-3)
    231  1.1    paulus #define Z_MEM_ERROR    (-4)
    232  1.1    paulus #define Z_BUF_ERROR    (-5)
    233  1.1    paulus /* error codes for the compression/decompression functions */
    234  1.1    paulus 
    235  1.1    paulus #define Z_BEST_SPEED             1
    236  1.1    paulus #define Z_BEST_COMPRESSION       9
    237  1.1    paulus #define Z_DEFAULT_COMPRESSION  (-1)
    238  1.1    paulus /* compression levels */
    239  1.1    paulus 
    240  1.1    paulus #define Z_FILTERED            1
    241  1.1    paulus #define Z_HUFFMAN_ONLY        2
    242  1.1    paulus #define Z_DEFAULT_STRATEGY    0
    243  1.1    paulus 
    244  1.1    paulus #define Z_BINARY   0
    245  1.1    paulus #define Z_ASCII    1
    246  1.1    paulus #define Z_UNKNOWN  2
    247  1.1    paulus /* Used to set the data_type field */
    248  1.1    paulus 
    249  1.1    paulus #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
    250  1.1    paulus 
    251  1.1    paulus extern char *zlib_version;
    252  1.1    paulus /* The application can compare zlib_version and ZLIB_VERSION for consistency.
    253  1.1    paulus    If the first character differs, the library code actually used is
    254  1.1    paulus    not compatible with the zlib.h header file used by the application.
    255  1.1    paulus  */
    256  1.1    paulus 
    257  1.1    paulus                         /* basic functions */
    258  1.1    paulus 
    259  1.1    paulus extern int deflateInit OF((z_stream *strm, int level));
    260  1.1    paulus /*
    261  1.1    paulus      Initializes the internal stream state for compression. The fields
    262  1.1    paulus    zalloc, zfree and opaque must be initialized before by the caller.
    263  1.1    paulus    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
    264  1.1    paulus    use default allocation functions.
    265  1.1    paulus 
    266  1.1    paulus      The compression level must be Z_DEFAULT_COMPRESSION, or between 1 and 9:
    267  1.1    paulus    1 gives best speed, 9 gives best compression. Z_DEFAULT_COMPRESSION requests
    268  1.1    paulus    a default compromise between speed and compression (currently equivalent
    269  1.1    paulus    to level 6).
    270  1.1    paulus 
    271  1.1    paulus      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
    272  1.1    paulus    enough memory, Z_STREAM_ERROR if level is not a valid compression level.
    273  1.1    paulus    msg is set to null if there is no error message.  deflateInit does not
    274  1.1    paulus    perform any compression: this will be done by deflate().
    275  1.1    paulus */
    276  1.1    paulus 
    277  1.1    paulus 
    278  1.1    paulus extern int deflate OF((z_stream *strm, int flush));
    279  1.1    paulus /*
    280  1.1    paulus   Performs one or both of the following actions:
    281  1.1    paulus 
    282  1.1    paulus   - Compress more input starting at next_in and update next_in and avail_in
    283  1.1    paulus     accordingly. If not all input can be processed (because there is not
    284  1.1    paulus     enough room in the output buffer), next_in and avail_in are updated and
    285  1.1    paulus     processing will resume at this point for the next call of deflate().
    286  1.1    paulus 
    287  1.1    paulus   - Provide more output starting at next_out and update next_out and avail_out
    288  1.1    paulus     accordingly. This action is forced if the parameter flush is non zero.
    289  1.1    paulus     Forcing flush frequently degrades the compression ratio, so this parameter
    290  1.1    paulus     should be set only when necessary (in interactive applications).
    291  1.1    paulus     Some output may be provided even if flush is not set.
    292  1.1    paulus 
    293  1.1    paulus   Before the call of deflate(), the application should ensure that at least
    294  1.1    paulus   one of the actions is possible, by providing more input and/or consuming
    295  1.1    paulus   more output, and updating avail_in or avail_out accordingly; avail_out
    296  1.1    paulus   should never be zero before the call. The application can consume the
    297  1.1    paulus   compressed output when it wants, for example when the output buffer is full
    298  1.1    paulus   (avail_out == 0), or after each call of deflate().
    299  1.1    paulus 
    300  1.1    paulus     If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
    301  1.1    paulus   block is terminated and flushed to the output buffer so that the
    302  1.1    paulus   decompressor can get all input data available so far. For method 9, a future
    303  1.1    paulus   variant on method 8, the current block will be flushed but not terminated.
    304  1.1    paulus   If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
    305  1.1    paulus   special marker is output and the compression dictionary is discarded; this
    306  1.1    paulus   is useful to allow the decompressor to synchronize if one compressed block
    307  1.1    paulus   has been damaged (see inflateSync below).  Flushing degrades compression and
    308  1.1    paulus   so should be used only when necessary.  Using Z_FULL_FLUSH too often can
    309  1.1    paulus   seriously degrade the compression. If deflate returns with avail_out == 0,
    310  1.1    paulus   this function must be called again with the same value of the flush
    311  1.1    paulus   parameter and more output space (updated avail_out), until the flush is
    312  1.1    paulus   complete (deflate returns with non-zero avail_out).
    313  1.1    paulus 
    314  1.1    paulus     If the parameter flush is set to Z_PACKET_FLUSH, the compression
    315  1.1    paulus   block is terminated, and a zero-length stored block is output,
    316  1.1    paulus   omitting the length bytes (the effect of this is that the 3-bit type
    317  1.1    paulus   code 000 for a stored block is output, and the output is then
    318  1.1    paulus   byte-aligned).  This is designed for use at the end of a PPP packet.
    319  1.1    paulus   In addition, if the current compression block contains all the data
    320  1.1    paulus   since the last Z_PACKET_FLUSH, it is never output as a stored block.
    321  1.1    paulus   If the current compression block output as a static or dynamic block
    322  1.1    paulus   would not be at least `minCompression' bytes smaller than the
    323  1.1    paulus   original data, then nothing is output for that block.  (The type
    324  1.1    paulus   code for the zero-length stored block is still output, resulting in
    325  1.1    paulus   a single zero byte being output for the whole packet.)
    326  1.1    paulus   `MinCompression' is a parameter to deflateInit2, or 0 if deflateInit
    327  1.1    paulus   is used.
    328  1.1    paulus 
    329  1.1    paulus     If the parameter flush is set to Z_FINISH, all pending input is processed,
    330  1.1    paulus   all pending output is flushed and deflate returns with Z_STREAM_END if there
    331  1.1    paulus   was enough output space; if deflate returns with Z_OK, this function must be
    332  1.1    paulus   called again with Z_FINISH and more output space (updated avail_out) but no
    333  1.1    paulus   more input data, until it returns with Z_STREAM_END or an error. After
    334  1.1    paulus   deflate has returned Z_STREAM_END, the only possible operations on the
    335  1.1    paulus   stream are deflateReset or deflateEnd.
    336  1.1    paulus 
    337  1.1    paulus     Z_FINISH can be used immediately after deflateInit if all the compression
    338  1.1    paulus   is to be done in a single step. In this case, avail_out must be at least
    339  1.1    paulus   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
    340  1.1    paulus   Z_STREAM_END, then it must be called again as described above.
    341  1.1    paulus 
    342  1.1    paulus     deflate() may update data_type if it can make a good guess about
    343  1.1    paulus   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
    344  1.1    paulus   binary. This field is only for information purposes and does not affect
    345  1.1    paulus   the compression algorithm in any manner.
    346  1.1    paulus 
    347  1.1    paulus     deflate() returns Z_OK if some progress has been made (more input
    348  1.1    paulus   processed or more output produced), Z_STREAM_END if all input has been
    349  1.1    paulus   consumed and all output has been produced (only when flush is set to
    350  1.1    paulus   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
    351  1.1    paulus   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
    352  1.1    paulus */
    353  1.1    paulus 
    354  1.1    paulus 
    355  1.1    paulus extern int deflateEnd OF((z_stream *strm));
    356  1.1    paulus /*
    357  1.1    paulus      All dynamically allocated data structures for this stream are freed.
    358  1.1    paulus    This function discards any unprocessed input and does not flush any
    359  1.1    paulus    pending output.
    360  1.1    paulus 
    361  1.1    paulus      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
    362  1.1    paulus    stream state was inconsistent. In the error case, msg may be set
    363  1.1    paulus    but then points to a static string (which must not be deallocated).
    364  1.1    paulus */
    365  1.1    paulus 
    366  1.1    paulus 
    367  1.1    paulus extern int inflateInit OF((z_stream *strm));
    368  1.1    paulus /*
    369  1.1    paulus      Initializes the internal stream state for decompression. The fields
    370  1.1    paulus    zalloc and zfree must be initialized before by the caller.  If zalloc and
    371  1.1    paulus    zfree are set to Z_NULL, inflateInit updates them to use default allocation
    372  1.1    paulus    functions.
    373  1.1    paulus 
    374  1.1    paulus      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
    375  1.1    paulus    enough memory.  msg is set to null if there is no error message.
    376  1.1    paulus    inflateInit does not perform any decompression: this will be done by
    377  1.1    paulus    inflate().
    378  1.1    paulus */
    379  1.1    paulus 
    380  1.2  christos 
    381  1.2  christos #if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL))
    382  1.2  christos #define inflate	inflate_ppp	/* FreeBSD already has an inflate :-( */
    383  1.2  christos #endif
    384  1.1    paulus 
    385  1.1    paulus extern int inflate OF((z_stream *strm, int flush));
    386  1.1    paulus /*
    387  1.1    paulus   Performs one or both of the following actions:
    388  1.1    paulus 
    389  1.1    paulus   - Decompress more input starting at next_in and update next_in and avail_in
    390  1.1    paulus     accordingly. If not all input can be processed (because there is not
    391  1.1    paulus     enough room in the output buffer), next_in is updated and processing
    392  1.1    paulus     will resume at this point for the next call of inflate().
    393  1.1    paulus 
    394  1.1    paulus   - Provide more output starting at next_out and update next_out and avail_out
    395  1.1    paulus     accordingly.  inflate() always provides as much output as possible
    396  1.1    paulus     (until there is no more input data or no more space in the output buffer).
    397  1.1    paulus 
    398  1.1    paulus   Before the call of inflate(), the application should ensure that at least
    399  1.1    paulus   one of the actions is possible, by providing more input and/or consuming
    400  1.1    paulus   more output, and updating the next_* and avail_* values accordingly.
    401  1.1    paulus   The application can consume the uncompressed output when it wants, for
    402  1.1    paulus   example when the output buffer is full (avail_out == 0), or after each
    403  1.1    paulus   call of inflate().
    404  1.1    paulus 
    405  1.1    paulus     If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
    406  1.1    paulus   inflate flushes as much output as possible to the output buffer. The
    407  1.1    paulus   flushing behavior of inflate is not specified for values of the flush
    408  1.1    paulus   parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
    409  1.1    paulus   current implementation actually flushes as much output as possible
    410  1.1    paulus   anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
    411  1.1    paulus   has been consumed, it is expecting to see the length field of a stored
    412  1.1    paulus   block; if not, it returns Z_DATA_ERROR.
    413  1.1    paulus 
    414  1.1    paulus     inflate() should normally be called until it returns Z_STREAM_END or an
    415  1.1    paulus   error. However if all decompression is to be performed in a single step
    416  1.1    paulus   (a single call of inflate), the parameter flush should be set to
    417  1.1    paulus   Z_FINISH. In this case all pending input is processed and all pending
    418  1.1    paulus   output is flushed; avail_out must be large enough to hold all the
    419  1.1    paulus   uncompressed data. (The size of the uncompressed data may have been saved
    420  1.1    paulus   by the compressor for this purpose.) The next operation on this stream must
    421  1.1    paulus   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
    422  1.1    paulus   is never required, but can be used to inform inflate that a faster routine
    423  1.1    paulus   may be used for the single inflate() call.
    424  1.1    paulus 
    425  1.1    paulus     inflate() returns Z_OK if some progress has been made (more input
    426  1.1    paulus   processed or more output produced), Z_STREAM_END if the end of the
    427  1.1    paulus   compressed data has been reached and all uncompressed output has been
    428  1.1    paulus   produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
    429  1.1    paulus   the stream structure was inconsistent (for example if next_in or next_out
    430  1.1    paulus   was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
    431  1.1    paulus   progress is possible or if there was not enough room in the output buffer
    432  1.1    paulus   when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
    433  1.1    paulus   call inflateSync to look for a good compression block.  */
    434  1.1    paulus 
    435  1.1    paulus 
    436  1.1    paulus extern int inflateEnd OF((z_stream *strm));
    437  1.1    paulus /*
    438  1.1    paulus      All dynamically allocated data structures for this stream are freed.
    439  1.1    paulus    This function discards any unprocessed input and does not flush any
    440  1.1    paulus    pending output.
    441  1.1    paulus 
    442  1.1    paulus      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
    443  1.1    paulus    was inconsistent. In the error case, msg may be set but then points to a
    444  1.1    paulus    static string (which must not be deallocated).
    445  1.1    paulus */
    446  1.1    paulus 
    447  1.1    paulus                         /* advanced functions */
    448  1.1    paulus 
    449  1.1    paulus /*
    450  1.1    paulus     The following functions are needed only in some special applications.
    451  1.1    paulus */
    452  1.1    paulus 
    453  1.1    paulus extern int deflateInit2 OF((z_stream *strm,
    454  1.1    paulus                             int  level,
    455  1.1    paulus                             int  method,
    456  1.1    paulus                             int  windowBits,
    457  1.1    paulus                             int  memLevel,
    458  1.1    paulus                             int  strategy,
    459  1.1    paulus 			    int  minCompression));
    460  1.1    paulus /*
    461  1.1    paulus      This is another version of deflateInit with more compression options. The
    462  1.1    paulus    fields next_in, zalloc and zfree must be initialized before by the caller.
    463  1.1    paulus 
    464  1.1    paulus      The method parameter is the compression method. It must be 8 in this
    465  1.1    paulus    version of the library. (Method 9 will allow a 64K history buffer and
    466  1.1    paulus    partial block flushes.)
    467  1.1    paulus 
    468  1.1    paulus      The windowBits parameter is the base two logarithm of the window size
    469  1.1    paulus    (the size of the history buffer).  It should be in the range 8..15 for this
    470  1.1    paulus    version of the library (the value 16 will be allowed for method 9). Larger
    471  1.1    paulus    values of this parameter result in better compression at the expense of
    472  1.1    paulus    memory usage. The default value is 15 if deflateInit is used instead.
    473  1.1    paulus 
    474  1.1    paulus     The memLevel parameter specifies how much memory should be allocated
    475  1.1    paulus    for the internal compression state. memLevel=1 uses minimum memory but
    476  1.1    paulus    is slow and reduces compression ratio; memLevel=9 uses maximum memory
    477  1.1    paulus    for optimal speed. The default value is 8. See zconf.h for total memory
    478  1.1    paulus    usage as a function of windowBits and memLevel.
    479  1.1    paulus 
    480  1.1    paulus      The strategy parameter is used to tune the compression algorithm. Use
    481  1.1    paulus    the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
    482  1.1    paulus    produced by a filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman
    483  1.1    paulus    encoding only (no string match).  Filtered data consists mostly of small
    484  1.1    paulus    values with a somewhat random distribution. In this case, the
    485  1.1    paulus    compression algorithm is tuned to compress them better. The strategy
    486  1.1    paulus    parameter only affects the compression ratio but not the correctness of
    487  1.1    paulus    the compressed output even if it is not set appropriately.
    488  1.1    paulus 
    489  1.1    paulus      The minCompression parameter specifies the minimum reduction in size
    490  1.1    paulus    required for a compressed block to be output when Z_PACKET_FLUSH is
    491  1.1    paulus    used (see the description of deflate above).
    492  1.1    paulus 
    493  1.1    paulus      If next_in is not null, the library will use this buffer to hold also
    494  1.1    paulus    some history information; the buffer must either hold the entire input
    495  1.1    paulus    data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
    496  1.1    paulus    is null, the library will allocate its own history buffer (and leave next_in
    497  1.1    paulus    null). next_out need not be provided here but must be provided by the
    498  1.1    paulus    application for the next call of deflate().
    499  1.1    paulus 
    500  1.1    paulus      If the history buffer is provided by the application, next_in must
    501  1.1    paulus    must never be changed by the application since the compressor maintains
    502  1.1    paulus    information inside this buffer from call to call; the application
    503  1.1    paulus    must provide more input only by increasing avail_in. next_in is always
    504  1.1    paulus    reset by the library in this case.
    505  1.1    paulus 
    506  1.1    paulus       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
    507  1.1    paulus    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
    508  1.1    paulus    an invalid method). msg is set to null if there is no error message.
    509  1.1    paulus    deflateInit2 does not perform any compression: this will be done by
    510  1.1    paulus    deflate().
    511  1.1    paulus */
    512  1.1    paulus 
    513  1.1    paulus extern int deflateCopy OF((z_stream *dest,
    514  1.1    paulus                            z_stream *source));
    515  1.1    paulus /*
    516  1.1    paulus      Sets the destination stream as a complete copy of the source stream.  If
    517  1.1    paulus    the source stream is using an application-supplied history buffer, a new
    518  1.1    paulus    buffer is allocated for the destination stream.  The compressed output
    519  1.1    paulus    buffer is always application-supplied. It's the responsibility of the
    520  1.1    paulus    application to provide the correct values of next_out and avail_out for the
    521  1.1    paulus    next call of deflate.
    522  1.1    paulus 
    523  1.1    paulus      This function is useful when several compression strategies will be
    524  1.1    paulus    tried, for example when there are several ways of pre-processing the input
    525  1.1    paulus    data with a filter. The streams that will be discarded should then be freed
    526  1.1    paulus    by calling deflateEnd.  Note that deflateCopy duplicates the internal
    527  1.1    paulus    compression state which can be quite large, so this strategy is slow and
    528  1.1    paulus    can consume lots of memory.
    529  1.1    paulus 
    530  1.1    paulus       deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
    531  1.1    paulus    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
    532  1.1    paulus    (such as zalloc being NULL). msg is left unchanged in both source and
    533  1.1    paulus    destination.
    534  1.1    paulus */
    535  1.1    paulus 
    536  1.1    paulus extern int deflateReset OF((z_stream *strm));
    537  1.1    paulus /*
    538  1.1    paulus      This function is equivalent to deflateEnd followed by deflateInit,
    539  1.1    paulus    but does not free and reallocate all the internal compression state.
    540  1.1    paulus    The stream will keep the same compression level and any other attributes
    541  1.1    paulus    that may have been set by deflateInit2.
    542  1.1    paulus 
    543  1.1    paulus       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
    544  1.1    paulus    stream state was inconsistent (such as zalloc or state being NULL).
    545  1.1    paulus */
    546  1.1    paulus 
    547  1.1    paulus extern int inflateInit2 OF((z_stream *strm,
    548  1.1    paulus                             int  windowBits));
    549  1.1    paulus /*
    550  1.1    paulus      This is another version of inflateInit with more compression options. The
    551  1.1    paulus    fields next_out, zalloc and zfree must be initialized before by the caller.
    552  1.1    paulus 
    553  1.1    paulus      The windowBits parameter is the base two logarithm of the maximum window
    554  1.1    paulus    size (the size of the history buffer).  It should be in the range 8..15 for
    555  1.1    paulus    this version of the library (the value 16 will be allowed soon). The
    556  1.1    paulus    default value is 15 if inflateInit is used instead. If a compressed stream
    557  1.1    paulus    with a larger window size is given as input, inflate() will return with
    558  1.1    paulus    the error code Z_DATA_ERROR instead of trying to allocate a larger window.
    559  1.1    paulus 
    560  1.1    paulus      If next_out is not null, the library will use this buffer for the history
    561  1.1    paulus    buffer; the buffer must either be large enough to hold the entire output
    562  1.1    paulus    data, or have at least 1<<windowBits bytes.  If next_out is null, the
    563  1.1    paulus    library will allocate its own buffer (and leave next_out null). next_in
    564  1.1    paulus    need not be provided here but must be provided by the application for the
    565  1.1    paulus    next call of inflate().
    566  1.1    paulus 
    567  1.1    paulus      If the history buffer is provided by the application, next_out must
    568  1.1    paulus    never be changed by the application since the decompressor maintains
    569  1.1    paulus    history information inside this buffer from call to call; the application
    570  1.1    paulus    can only reset next_out to the beginning of the history buffer when
    571  1.1    paulus    avail_out is zero and all output has been consumed.
    572  1.1    paulus 
    573  1.1    paulus       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
    574  1.1    paulus    not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
    575  1.1    paulus    windowBits < 8). msg is set to null if there is no error message.
    576  1.1    paulus    inflateInit2 does not perform any decompression: this will be done by
    577  1.1    paulus    inflate().
    578  1.1    paulus */
    579  1.1    paulus 
    580  1.1    paulus extern int inflateSync OF((z_stream *strm));
    581  1.1    paulus /*
    582  1.1    paulus     Skips invalid compressed data until the special marker (see deflate()
    583  1.1    paulus   above) can be found, or until all available input is skipped. No output
    584  1.1    paulus   is provided.
    585  1.1    paulus 
    586  1.1    paulus     inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
    587  1.1    paulus   if no more input was provided, Z_DATA_ERROR if no marker has been found,
    588  1.1    paulus   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
    589  1.1    paulus   case, the application may save the current current value of total_in which
    590  1.1    paulus   indicates where valid compressed data was found. In the error case, the
    591  1.1    paulus   application may repeatedly call inflateSync, providing more input each time,
    592  1.1    paulus   until success or end of the input data.
    593  1.1    paulus */
    594  1.1    paulus 
    595  1.1    paulus extern int inflateReset OF((z_stream *strm));
    596  1.1    paulus /*
    597  1.1    paulus      This function is equivalent to inflateEnd followed by inflateInit,
    598  1.1    paulus    but does not free and reallocate all the internal decompression state.
    599  1.1    paulus    The stream will keep attributes that may have been set by inflateInit2.
    600  1.1    paulus 
    601  1.1    paulus       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
    602  1.1    paulus    stream state was inconsistent (such as zalloc or state being NULL).
    603  1.1    paulus */
    604  1.1    paulus 
    605  1.1    paulus extern int inflateIncomp OF((z_stream *strm));
    606  1.1    paulus /*
    607  1.1    paulus      This function adds the data at next_in (avail_in bytes) to the output
    608  1.1    paulus    history without performing any output.  There must be no pending output,
    609  1.1    paulus    and the decompressor must be expecting to see the start of a block.
    610  1.1    paulus    Calling this function is equivalent to decompressing a stored block
    611  1.1    paulus    containing the data at next_in (except that the data is not output).
    612  1.1    paulus */
    613  1.1    paulus 
    614  1.1    paulus                         /* checksum functions */
    615  1.1    paulus 
    616  1.1    paulus /*
    617  1.1    paulus      This function is not related to compression but is exported
    618  1.1    paulus    anyway because it might be useful in applications using the
    619  1.1    paulus    compression library.
    620  1.1    paulus */
    621  1.1    paulus 
    622  1.1    paulus extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
    623  1.1    paulus 
    624  1.1    paulus /*
    625  1.1    paulus      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
    626  1.1    paulus    return the updated checksum. If buf is NULL, this function returns
    627  1.1    paulus    the required initial value for the checksum.
    628  1.1    paulus    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
    629  1.1    paulus    much faster. Usage example:
    630  1.1    paulus 
    631  1.1    paulus      uLong adler = adler32(0L, Z_NULL, 0);
    632  1.1    paulus 
    633  1.1    paulus      while (read_buffer(buffer, length) != EOF) {
    634  1.1    paulus        adler = adler32(adler, buffer, length);
    635  1.1    paulus      }
    636  1.1    paulus      if (adler != original_adler) error();
    637  1.1    paulus */
    638  1.1    paulus 
    639  1.1    paulus #ifndef _Z_UTIL_H
    640  1.1    paulus     struct internal_state {int dummy;}; /* hack for buggy compilers */
    641  1.1    paulus #endif
    642  1.1    paulus 
    643  1.1    paulus #endif /* _ZLIB_H */
    644