1c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* zlib.h -- interface of the 'zlib' general purpose compression library
2c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
3c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
4c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
5c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  This software is provided 'as-is', without any express or implied
6c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  warranty.  In no event will the authors be held liable for any damages
7c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  arising from the use of this software.
8c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
9c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Permission is granted to anyone to use this software for any purpose,
10c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  including commercial applications, and to alter it and redistribute it
11c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  freely, subject to the following restrictions:
12c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
13c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  1. The origin of this software must not be misrepresented; you must not
14c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     claim that you wrote the original software. If you use this software
15c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     in a product, an acknowledgment in the product documentation would be
16c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     appreciated but is not required.
17c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  2. Altered source versions must be plainly marked as such, and must not be
18c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     misrepresented as being the original software.
19c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  3. This notice may not be removed or altered from any source distribution.
20c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
21c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Jean-loup Gailly        Mark Adler
22c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  jloup@gzip.org          madler@alumni.caltech.edu
23c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
24c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
25c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  The data format used by the zlib library is described by RFCs (Request for
26c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
27c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
28c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
29c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
30c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#ifndef _ZLIB_H
31c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define _ZLIB_H
32c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
33c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#include <linux/zconf.h>
34c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
35c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* zlib deflate based on ZLIB_VERSION "1.1.3" */
36c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* zlib inflate based on ZLIB_VERSION "1.2.3" */
37c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
38c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
39c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  This is a modified version of zlib for use inside the Linux kernel.
40c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  The main changes are to perform all memory allocation in advance.
41c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
42c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Inflation Changes:
43c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    * Z_PACKET_FLUSH is added and used by ppp_deflate. Before returning
44c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      this checks there is no more input data available and the next data
45c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      is a STORED block. It also resets the mode to be read for the next
46c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      data, all as per PPP requirements.
47c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    * Addition of zlib_inflateIncomp which copies incompressible data into
48c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      the history window and adjusts the accoutning without calling
49c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      zlib_inflate itself to inflate the data.
50c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
51c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
52c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
53c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The 'zlib' compression library provides in-memory compression and
54c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  decompression functions, including integrity checks of the uncompressed
55c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  data.  This version of the library supports only one compression method
56c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  (deflation) but other algorithms will be added later and will have the same
57c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  stream interface.
58c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
59c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Compression can be done in a single step if the buffers are large
60c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  enough (for example if an input file is mmap'ed), or can be done by
61c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  repeated calls of the compression function.  In the latter case, the
62c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  application must provide more input and/or consume the output
63c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  (providing more output space) before each call.
64c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
65c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The compressed data format used by default by the in-memory functions is
66c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
67c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  around a deflate stream, which is itself documented in RFC 1951.
68c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
69c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The library also supports reading and writing files in gzip (.gz) format
70c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  with an interface similar to that of stdio.
71c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
72c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The zlib format was designed to be compact and fast for use in memory
73c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  and on communications channels.  The gzip format was designed for single-
74c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  file compression on file systems, has a larger header than zlib to maintain
75c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  directory information, and uses a different, slower check method than zlib.
76c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
77c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The library does not install any signal handler. The decoder checks
78c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the consistency of the compressed data, so the library should never
79c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  crash even in case of corrupted input.
80c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
81c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
82c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Querustruct internal_state;
83c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
84c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Querutypedef struct z_stream_s {
85c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    Byte    *next_in;   /* next input byte */
86c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    uInt     avail_in;  /* number of bytes available at next_in */
87c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    uLong    total_in;  /* total nb of input bytes read so far */
88c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
89c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    Byte    *next_out;  /* next output byte should be put there */
90c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    uInt     avail_out; /* remaining free space at next_out */
91c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    uLong    total_out; /* total nb of bytes output so far */
92c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
93c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    char     *msg;      /* last error message, NULL if no error */
94c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    struct internal_state *state; /* not visible by applications */
95c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
96c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    void     *workspace; /* memory allocated for this stream */
97c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
98c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    int     data_type;  /* best guess about the data type: ascii or binary */
99c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    uLong   adler;      /* adler32 value of the uncompressed data */
100c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    uLong   reserved;   /* reserved for future use */
101c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru} z_stream;
102c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
103c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Querutypedef z_stream *z_streamp;
104c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
105c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
106c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   The application must update next_in and avail_in when avail_in has
107c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   dropped to zero. It must update next_out and avail_out when avail_out
108c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   has dropped to zero. The application must initialize zalloc, zfree and
109c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   opaque before calling the init function. All other fields are set by the
110c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   compression library and must not be updated by the application.
111c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
112c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   The opaque value provided by the application will be passed as the first
113c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   parameter for calls of zalloc and zfree. This can be useful for custom
114c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   memory management. The compression library attaches no meaning to the
115c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   opaque value.
116c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
117c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   zalloc must return NULL if there is not enough memory for the object.
118c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   If zlib is used in a multi-threaded application, zalloc and zfree must be
119c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   thread safe.
120c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
121c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   On 16-bit systems, the functions zalloc and zfree must be able to allocate
122c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   exactly 65536 bytes, but will not be required to allocate more than this
123c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
124c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   pointers returned by zalloc for objects of exactly 65536 bytes *must*
125c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   have their offset normalized to zero. The default allocation function
126c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   provided by this library ensures this (see zutil.c). To reduce memory
127c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   requirements and avoid any allocation of 64K objects, at the expense of
128c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
129c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
130c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   The fields total_in and total_out can be used for statistics or
131c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   progress reports. After compression, total_in holds the total size of
132c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   the uncompressed data and may be saved for use in the decompressor
133c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   (particularly if the decompressor wants to decompress everything in
134c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   a single step).
135c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
136c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
137c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                        /* constants */
138c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
139c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_NO_FLUSH      0
140c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
141c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_PACKET_FLUSH  2
142c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_SYNC_FLUSH    3
143c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_FULL_FLUSH    4
144c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_FINISH        5
145c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_BLOCK         6 /* Only for inflate at present */
146c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* Allowed flush values; see deflate() and inflate() below for details */
147c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
148c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_OK            0
149c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_STREAM_END    1
150c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_NEED_DICT     2
151c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_ERRNO        (-1)
152c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_STREAM_ERROR (-2)
153c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_DATA_ERROR   (-3)
154c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_MEM_ERROR    (-4)
155c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_BUF_ERROR    (-5)
156c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_VERSION_ERROR (-6)
157c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* Return codes for the compression/decompression functions. Negative
158c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru * values are errors, positive values are used for special but normal events.
159c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru */
160c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
161c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_NO_COMPRESSION         0
162c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_BEST_SPEED             1
163c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_BEST_COMPRESSION       9
164c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_DEFAULT_COMPRESSION  (-1)
165c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* compression levels */
166c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
167c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_FILTERED            1
168c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_HUFFMAN_ONLY        2
169c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_DEFAULT_STRATEGY    0
170c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* compression strategy; see deflateInit2() below for details */
171c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
172c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_BINARY   0
173c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_ASCII    1
174c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_UNKNOWN  2
175c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* Possible values of the data_type field */
176c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
177c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define Z_DEFLATED   8
178c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/* The deflate compression method (the only one supported in this version) */
179c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
180c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                        /* basic functions */
181c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
182c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflate_workspacesize (void);
183c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
184c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Returns the number of bytes that needs to be allocated for a per-
185c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   stream workspace.  A pointer to this number of bytes should be
186c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   returned in stream->workspace before calling zlib_deflateInit().
187c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
188c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
189c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
190c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int deflateInit (z_streamp strm, int level);
191c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
192c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Initializes the internal stream state for compression. The fields
193c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   zalloc, zfree and opaque must be initialized before by the caller.
194c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   If zalloc and zfree are set to NULL, deflateInit updates them to
195c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   use default allocation functions.
196c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
197c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
198c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   1 gives best speed, 9 gives best compression, 0 gives no compression at
199c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   all (the input data is simply copied a block at a time).
200c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Z_DEFAULT_COMPRESSION requests a default compromise between speed and
201c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   compression (currently equivalent to level 6).
202c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
203c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
204c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   enough memory, Z_STREAM_ERROR if level is not a valid compression level,
205c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
206c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   with the version assumed by the caller (ZLIB_VERSION).
207c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   msg is set to null if there is no error message.  deflateInit does not
208c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   perform any compression: this will be done by deflate().
209c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
210c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
211c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
212c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflate (z_streamp strm, int flush);
213c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
214c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    deflate compresses as much data as possible, and stops when the input
215c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  buffer becomes empty or the output buffer becomes full. It may introduce some
216c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  output latency (reading input without producing any output) except when
217c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  forced to flush.
218c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
219c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    The detailed semantics are as follows. deflate performs one or both of the
220c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  following actions:
221c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
222c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  - Compress more input starting at next_in and update next_in and avail_in
223c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    accordingly. If not all input can be processed (because there is not
224c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    enough room in the output buffer), next_in and avail_in are updated and
225c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    processing will resume at this point for the next call of deflate().
226c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
227c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  - Provide more output starting at next_out and update next_out and avail_out
228c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    accordingly. This action is forced if the parameter flush is non zero.
229c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    Forcing flush frequently degrades the compression ratio, so this parameter
230c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    should be set only when necessary (in interactive applications).
231c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    Some output may be provided even if flush is not set.
232c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
233c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Before the call of deflate(), the application should ensure that at least
234c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  one of the actions is possible, by providing more input and/or consuming
235c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  more output, and updating avail_in or avail_out accordingly; avail_out
236c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  should never be zero before the call. The application can consume the
237c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  compressed output when it wants, for example when the output buffer is full
238c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
239c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  and with zero avail_out, it must be called again after making room in the
240c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  output buffer because there might be more output pending.
241c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
242c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
243c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  flushed to the output buffer and the output is aligned on a byte boundary, so
244c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  that the decompressor can get all input data available so far. (In particular
245c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  avail_in is zero after the call if enough output space has been provided
246c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  before the call.)  Flushing may degrade compression for some compression
247c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  algorithms and so it should be used only when necessary.
248c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
249c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    If flush is set to Z_FULL_FLUSH, all output is flushed as with
250c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Z_SYNC_FLUSH, and the compression state is reset so that decompression can
251c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  restart from this point if previous compressed data has been damaged or if
252c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
253c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the compression.
254c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
255c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    If deflate returns with avail_out == 0, this function must be called again
256c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  with the same value of the flush parameter and more output space (updated
257c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  avail_out), until the flush is complete (deflate returns with non-zero
258c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  avail_out).
259c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
260c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    If the parameter flush is set to Z_FINISH, pending input is processed,
261c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  pending output is flushed and deflate returns with Z_STREAM_END if there
262c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  was enough output space; if deflate returns with Z_OK, this function must be
263c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  called again with Z_FINISH and more output space (updated avail_out) but no
264c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  more input data, until it returns with Z_STREAM_END or an error. After
265c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  deflate has returned Z_STREAM_END, the only possible operations on the
266c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  stream are deflateReset or deflateEnd.
267c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
268c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    Z_FINISH can be used immediately after deflateInit if all the compression
269c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  is to be done in a single step. In this case, avail_out must be at least
270c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  0.1% larger than avail_in plus 12 bytes.  If deflate does not return
271c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Z_STREAM_END, then it must be called again as described above.
272c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
273c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    deflate() sets strm->adler to the adler32 checksum of all input read
274c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  so far (that is, total_in bytes).
275c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
276c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    deflate() may update data_type if it can make a good guess about
277c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
278c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  binary. This field is only for information purposes and does not affect
279c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the compression algorithm in any manner.
280c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
281c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    deflate() returns Z_OK if some progress has been made (more input
282c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  processed or more output produced), Z_STREAM_END if all input has been
283c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  consumed and all output has been produced (only when flush is set to
284c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
285c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
286c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  (for example avail_in or avail_out was zero).
287c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
288c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
289c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
290c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflateEnd (z_streamp strm);
291c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
292c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     All dynamically allocated data structures for this stream are freed.
293c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   This function discards any unprocessed input and does not flush any
294c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   pending output.
295c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
296c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
297c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
298c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   prematurely (some input or output was discarded). In the error case,
299c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   msg may be set but then points to a static string (which must not be
300c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   deallocated).
301c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
302c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
303c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
304c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflate_workspacesize (void);
305c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
306c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Returns the number of bytes that needs to be allocated for a per-
307c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   stream workspace.  A pointer to this number of bytes should be
308c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   returned in stream->workspace before calling zlib_inflateInit().
309c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
310c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
311c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
312c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateInit (z_streamp strm);
313c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
314c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Initializes the internal stream state for decompression. The fields
315c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   next_in, avail_in, and workspace must be initialized before by
316c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   the caller. If next_in is not NULL and avail_in is large enough (the exact
317c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   value depends on the compression method), inflateInit determines the
318c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   compression method from the zlib header and allocates all data structures
319c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   accordingly; otherwise the allocation will be deferred to the first call of
320c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   inflate.  If zalloc and zfree are set to NULL, inflateInit updates them to
321c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   use default allocation functions.
322c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
323c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
324c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
325c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   version assumed by the caller.  msg is set to null if there is no error
326c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   message. inflateInit does not perform any decompression apart from reading
327c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   the zlib header if present: this will be done by inflate().  (So next_in and
328c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   avail_in may be modified, but next_out and avail_out are unchanged.)
329c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
330c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
331c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
332c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflate (z_streamp strm, int flush);
333c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
334c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    inflate decompresses as much data as possible, and stops when the input
335c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  buffer becomes empty or the output buffer becomes full. It may introduce
336c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  some output latency (reading input without producing any output) except when
337c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  forced to flush.
338c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
339c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  The detailed semantics are as follows. inflate performs one or both of the
340c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  following actions:
341c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
342c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  - Decompress more input starting at next_in and update next_in and avail_in
343c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    accordingly. If not all input can be processed (because there is not
344c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    enough room in the output buffer), next_in is updated and processing
345c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    will resume at this point for the next call of inflate().
346c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
347c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  - Provide more output starting at next_out and update next_out and avail_out
348c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    accordingly.  inflate() provides as much output as possible, until there
349c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    is no more input data or no more space in the output buffer (see below
350c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    about the flush parameter).
351c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
352c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Before the call of inflate(), the application should ensure that at least
353c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  one of the actions is possible, by providing more input and/or consuming
354c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  more output, and updating the next_* and avail_* values accordingly.
355c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  The application can consume the uncompressed output when it wants, for
356c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  example when the output buffer is full (avail_out == 0), or after each
357c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  call of inflate(). If inflate returns Z_OK and with zero avail_out, it
358c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  must be called again after making room in the output buffer because there
359c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  might be more output pending.
360c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
361c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
362c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
363c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  output as possible to the output buffer. Z_BLOCK requests that inflate() stop
364c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  if and when it gets to the next deflate block boundary. When decoding the
365c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  zlib or gzip format, this will cause inflate() to return immediately after
366c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the header and before the first block. When doing a raw inflate, inflate()
367c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  will go ahead and process the first block, and will return when it gets to
368c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  the end of that block, or when it runs out of data.
369c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
370c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    The Z_BLOCK option assists in appending to or combining deflate streams.
371c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Also to assist in this, on return inflate() will set strm->data_type to the
372c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  number of unused bits in the last byte taken from strm->next_in, plus 64
373c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  if inflate() is currently decoding the last block in the deflate stream,
374c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  plus 128 if inflate() returned immediately after decoding an end-of-block
375c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  code or decoding the complete header up to just before the first byte of the
376c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  deflate stream. The end-of-block will not be indicated until all of the
377c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  uncompressed data from that block has been written to strm->next_out.  The
378c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  number of unused bits may in general be greater than seven, except when
379c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  bit 7 of data_type is set, in which case the number of unused bits will be
380c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  less than eight.
381c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
382c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    inflate() should normally be called until it returns Z_STREAM_END or an
383c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  error. However if all decompression is to be performed in a single step
384c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  (a single call of inflate), the parameter flush should be set to
385c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Z_FINISH. In this case all pending input is processed and all pending
386c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  output is flushed; avail_out must be large enough to hold all the
387c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  uncompressed data. (The size of the uncompressed data may have been saved
388c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  by the compressor for this purpose.) The next operation on this stream must
389c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
390c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  is never required, but can be used to inform inflate that a faster approach
391c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  may be used for the single inflate() call.
392c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
393c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     In this implementation, inflate() always flushes as much output as
394c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  possible to the output buffer, and always uses the faster approach on the
395c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  first call. So the only effect of the flush parameter in this implementation
396c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  is on the return value of inflate(), as noted below, or when it returns early
397c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  because Z_BLOCK is used.
398c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
399c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     If a preset dictionary is needed after this call (see inflateSetDictionary
400c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  below), inflate sets strm->adler to the adler32 checksum of the dictionary
401c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
402c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  strm->adler to the adler32 checksum of all output produced so far (that is,
403c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
404c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  below. At the end of the stream, inflate() checks that its computed adler32
405c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  checksum is equal to that saved by the compressor and returns Z_STREAM_END
406c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  only if the checksum is correct.
407c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
408c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    inflate() will decompress and check either zlib-wrapped or gzip-wrapped
409c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  deflate data.  The header type is detected automatically.  Any information
410c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  contained in the gzip header is not retained, so applications that need that
411c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  information should instead use raw inflate, see inflateInit2() below, or
412c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  inflateBack() and perform their own processing of the gzip header and
413c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  trailer.
414c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
415c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    inflate() returns Z_OK if some progress has been made (more input processed
416c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  or more output produced), Z_STREAM_END if the end of the compressed data has
417c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  been reached and all uncompressed output has been produced, Z_NEED_DICT if a
418c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
419c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  corrupted (input stream not conforming to the zlib format or incorrect check
420c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
421c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
422c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
423c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
424c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  inflate() can be called again with more input and more output space to
425c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  continue decompressing. If Z_DATA_ERROR is returned, the application may then
426c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  call inflateSync() to look for a good compression block if a partial recovery
427c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  of the data is desired.
428c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
429c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
430c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
431c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateEnd (z_streamp strm);
432c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
433c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     All dynamically allocated data structures for this stream are freed.
434c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   This function discards any unprocessed input and does not flush any
435c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   pending output.
436c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
437c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
438c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   was inconsistent. In the error case, msg may be set but then points to a
439c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   static string (which must not be deallocated).
440c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
441c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
442c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                        /* Advanced functions */
443c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
444c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
445c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    The following functions are needed only in some special applications.
446c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
447c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
448c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
449c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int deflateInit2 (z_streamp strm,
450c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                     int  level,
451c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                     int  method,
452c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                     int  windowBits,
453c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                     int  memLevel,
454c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                     int  strategy);
455c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
456c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     This is another version of deflateInit with more compression options. The
457c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   fields next_in, zalloc, zfree and opaque must be initialized before by
458c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   the caller.
459c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
460c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The method parameter is the compression method. It must be Z_DEFLATED in
461c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   this version of the library.
462c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
463c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The windowBits parameter is the base two logarithm of the window size
464c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   (the size of the history buffer).  It should be in the range 8..15 for this
465c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   version of the library. Larger values of this parameter result in better
466c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   compression at the expense of memory usage. The default value is 15 if
467c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   deflateInit is used instead.
468c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
469c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The memLevel parameter specifies how much memory should be allocated
470c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   for the internal compression state. memLevel=1 uses minimum memory but
471c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   is slow and reduces compression ratio; memLevel=9 uses maximum memory
472c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   for optimal speed. The default value is 8. See zconf.h for total memory
473c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   usage as a function of windowBits and memLevel.
474c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
475c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The strategy parameter is used to tune the compression algorithm. Use the
476c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
477c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
478c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   string match).  Filtered data consists mostly of small values with a
479c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   somewhat random distribution. In this case, the compression algorithm is
480c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   tuned to compress them better. The effect of Z_FILTERED is to force more
481c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Huffman coding and less string matching; it is somewhat intermediate
482c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
483c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   the compression ratio but not the correctness of the compressed output even
484c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   if it is not set appropriately.
485c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
486c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
487c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
488c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   method). msg is set to null if there is no error message.  deflateInit2 does
489c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   not perform any compression: this will be done by deflate().
490c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
491c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
492c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#if 0
493c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflateSetDictionary (z_streamp strm,
494c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru						     const Byte *dictionary,
495c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru						     uInt  dictLength);
496c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#endif
497c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
498c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Initializes the compression dictionary from the given byte sequence
499c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   without producing any compressed output. This function must be called
500c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   immediately after deflateInit, deflateInit2 or deflateReset, before any
501c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   call of deflate. The compressor and decompressor must use exactly the same
502c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   dictionary (see inflateSetDictionary).
503c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
504c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The dictionary should consist of strings (byte sequences) that are likely
505c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   to be encountered later in the data to be compressed, with the most commonly
506c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   used strings preferably put towards the end of the dictionary. Using a
507c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   dictionary is most useful when the data to be compressed is short and can be
508c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   predicted with good accuracy; the data can then be compressed better than
509c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   with the default empty dictionary.
510c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
511c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Depending on the size of the compression data structures selected by
512c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   deflateInit or deflateInit2, a part of the dictionary may in effect be
513c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   discarded, for example if the dictionary is larger than the window size in
514c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   deflate or deflate2. Thus the strings most likely to be useful should be
515c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   put at the end of the dictionary, not at the front.
516c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
517c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Upon return of this function, strm->adler is set to the Adler32 value
518c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   of the dictionary; the decompressor may later use this value to determine
519c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   which dictionary has been used by the compressor. (The Adler32 value
520c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   applies to the whole dictionary even if only a subset of the dictionary is
521c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   actually used by the compressor.)
522c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
523c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
524c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   parameter is invalid (such as NULL dictionary) or the stream state is
525c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   inconsistent (for example if deflate has already been called for this stream
526c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   or if the compression method is bsort). deflateSetDictionary does not
527c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   perform any compression: this will be done by deflate().
528c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
529c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
530c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#if 0
531c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflateCopy (z_streamp dest, z_streamp source);
532c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#endif
533c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
534c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
535c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Sets the destination stream as a complete copy of the source stream.
536c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
537c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     This function can be useful when several compression strategies will be
538c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   tried, for example when there are several ways of pre-processing the input
539c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   data with a filter. The streams that will be discarded should then be freed
540c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   by calling deflateEnd.  Note that deflateCopy duplicates the internal
541c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   compression state which can be quite large, so this strategy is slow and
542c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   can consume lots of memory.
543c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
544c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
545c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
546c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   (such as zalloc being NULL). msg is left unchanged in both source and
547c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   destination.
548c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
549c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
550c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflateReset (z_streamp strm);
551c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
552c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     This function is equivalent to deflateEnd followed by deflateInit,
553c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   but does not free and reallocate all the internal compression state.
554c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   The stream will keep the same compression level and any other attributes
555c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   that may have been set by deflateInit2.
556c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
557c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
558c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   stream state was inconsistent (such as zalloc or state being NULL).
559c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
560c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
561c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Querustatic inline unsigned long deflateBound(unsigned long s)
562c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru{
563c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru	return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11;
564c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru}
565c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
566c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#if 0
567c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflateParams (z_streamp strm, int level, int strategy);
568c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#endif
569c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
570c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Dynamically update the compression level and compression strategy.  The
571c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   interpretation of level and strategy is as in deflateInit2.  This can be
572c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   used to switch between compression and straight copy of the input data, or
573c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   to switch to a different kind of input data requiring a different
574c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   strategy. If the compression level is changed, the input available so far
575c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   is compressed with the old level (and may be flushed); the new level will
576c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   take effect only at the next call of deflate().
577c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
578c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Before the call of deflateParams, the stream state must be set as for
579c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   a call of deflate(), since the currently available input may have to
580c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   be compressed and flushed. In particular, strm->avail_out must be non-zero.
581c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
582c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
583c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
584c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   if strm->avail_out was zero.
585c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
586c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
587c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
588c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int inflateInit2 (z_streamp strm, int  windowBits);
589c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
590c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     This is another version of inflateInit with an extra parameter. The
591c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
592c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   before by the caller.
593c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
594c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     The windowBits parameter is the base two logarithm of the maximum window
595c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   size (the size of the history buffer).  It should be in the range 8..15 for
596c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   this version of the library. The default value is 15 if inflateInit is used
597c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   instead. windowBits must be greater than or equal to the windowBits value
598c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   provided to deflateInit2() while compressing, or it must be equal to 15 if
599c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   deflateInit2() was not used. If a compressed stream with a larger window
600c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   size is given as input, inflate() will return with the error code
601c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Z_DATA_ERROR instead of trying to allocate a larger window.
602c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
603c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
604c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   determines the window size. inflate() will then process raw deflate data,
605c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   not looking for a zlib or gzip header, not generating a check value, and not
606c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   looking for any check values for comparison at the end of the stream. This
607c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   is for use with other formats that use the deflate compressed data format
608c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   such as zip.  Those formats provide their own check values. If a custom
609c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   format is developed using the raw deflate format for compressed data, it is
610c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   recommended that a check value such as an adler32 or a crc32 be applied to
611c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   the uncompressed data as is done in the zlib, gzip, and zip formats.  For
612c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   most applications, the zlib format should be used as is. Note that comments
613c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   above on the use in deflateInit2() applies to the magnitude of windowBits.
614c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
615c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     windowBits can also be greater than 15 for optional gzip decoding. Add
616c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   32 to windowBits to enable zlib and gzip decoding with automatic header
617c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   detection, or add 16 to decode only the gzip format (the zlib format will
618c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is
619c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   a crc32 instead of an adler32.
620c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
621c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
622c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
623c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   is set to null if there is no error message.  inflateInit2 does not perform
624c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   any decompression apart from reading the zlib header if present: this will
625c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   be done by inflate(). (So next_in and avail_in may be modified, but next_out
626c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   and avail_out are unchanged.)
627c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
628c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
629c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateSetDictionary (z_streamp strm,
630c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru						     const Byte *dictionary,
631c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru						     uInt  dictLength);
632c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
633c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     Initializes the decompression dictionary from the given uncompressed byte
634c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   sequence. This function must be called immediately after a call of inflate,
635c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
636c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   can be determined from the adler32 value returned by that call of inflate.
637c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   The compressor and decompressor must use exactly the same dictionary (see
638c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   deflateSetDictionary).  For raw inflate, this function can be called
639c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   immediately after inflateInit2() or inflateReset() and before any call of
640c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   inflate() to set the dictionary.  The application must insure that the
641c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   dictionary that was used for compression is provided.
642c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
643c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
644c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   parameter is invalid (such as NULL dictionary) or the stream state is
645c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
646c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   expected one (incorrect adler32 value). inflateSetDictionary does not
647c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   perform any decompression: this will be done by subsequent calls of
648c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   inflate().
649c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
650c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
651c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#if 0
652c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateSync (z_streamp strm);
653c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#endif
654c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
655c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    Skips invalid compressed data until a full flush point (see above the
656c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  description of deflate with Z_FULL_FLUSH) can be found, or until all
657c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  available input is skipped. No output is provided.
658c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
659c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
660c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  if no more input was provided, Z_DATA_ERROR if no flush point has been found,
661c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
662c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  case, the application may save the current current value of total_in which
663c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  indicates where valid compressed data was found. In the error case, the
664c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  application may repeatedly call inflateSync, providing more input each time,
665c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru  until success or end of the input data.
666c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
667c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
668c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateReset (z_streamp strm);
669c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
670c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     This function is equivalent to inflateEnd followed by inflateInit,
671c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   but does not free and reallocate all the internal decompression state.
672c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   The stream will keep attributes that may have been set by inflateInit2.
673c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
674c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
675c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   stream state was inconsistent (such as zalloc or state being NULL).
676c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
677c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
678c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateIncomp (z_stream *strm);
679c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru/*
680c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru     This function adds the data at next_in (avail_in bytes) to the output
681c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   history without performing any output.  There must be no pending output,
682c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   and the decompressor must be expecting to see the start of a block.
683c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   Calling this function is equivalent to decompressing a stored block
684c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru   containing the data at next_in (except that the data is not output).
685c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru*/
686c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
687c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define zlib_deflateInit(strm, level) \
688c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru	zlib_deflateInit2((strm), (level), Z_DEFLATED, MAX_WBITS, \
689c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru			      DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY)
690c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#define zlib_inflateInit(strm) \
691c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru	zlib_inflateInit2((strm), DEF_WBITS)
692c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
693c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_deflateInit2(z_streamp strm, int  level, int  method,
694c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                      int windowBits, int memLevel,
695c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru                                      int strategy);
696c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queruextern int zlib_inflateInit2(z_streamp strm, int  windowBits);
697c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
698c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
699c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru    struct internal_state {int dummy;}; /* hack for buggy compilers */
700c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#endif
701c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru
702c559cd81139f97cecad1ad91a0b2e25a5936d53Jean-Baptiste Queru#endif /* _ZLIB_H */
703