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