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