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