annotate lib/zlib/zlib.h @ 1414:110eac219e5a

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