summaryrefslogtreecommitdiff
path: root/zlib.h
diff options
context:
space:
mode:
Diffstat (limited to 'zlib.h')
-rw-r--r--zlib.h887
1 files changed, 458 insertions, 429 deletions
diff --git a/zlib.h b/zlib.h
index 11d6902..a751b30 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.3.5, Jan 8th, 2010 2 version 1.2.3.6, Jan 17th, 2010
3 3
4 Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
5 5
@@ -37,44 +37,43 @@
37extern "C" { 37extern "C" {
38#endif 38#endif
39 39
40#define ZLIB_VERSION "1.2.3.5" 40#define ZLIB_VERSION "1.2.3.6"
41#define ZLIB_VERNUM 0x1235 41#define ZLIB_VERNUM 0x1236
42#define ZLIB_VER_MAJOR 1 42#define ZLIB_VER_MAJOR 1
43#define ZLIB_VER_MINOR 2 43#define ZLIB_VER_MINOR 2
44#define ZLIB_VER_REVISION 3 44#define ZLIB_VER_REVISION 3
45 45
46/* 46/*
47 The 'zlib' compression library provides in-memory compression and 47 The 'zlib' compression library provides in-memory compression and
48 decompression functions, including integrity checks of the uncompressed 48 decompression functions, including integrity checks of the uncompressed data.
49 data. This version of the library supports only one compression method 49 This version of the library supports only one compression method (deflation)
50 (deflation) but other algorithms will be added later and will have the same 50 but other algorithms will be added later and will have the same stream
51 stream interface. 51 interface.
52 52
53 Compression can be done in a single step if the buffers are large 53 Compression can be done in a single step if the buffers are large enough,
54 enough (for example if an input file is mmap'ed), or can be done by 54 or can be done by repeated calls of the compression function. In the latter
55 repeated calls of the compression function. In the latter case, the 55 case, the application must provide more input and/or consume the output
56 application must provide more input and/or consume the output
57 (providing more output space) before each call. 56 (providing more output space) before each call.
58 57
59 The compressed data format used by default by the in-memory functions is 58 The compressed data format used by default by the in-memory functions is
60 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 59 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
61 around a deflate stream, which is itself documented in RFC 1951. 60 around a deflate stream, which is itself documented in RFC 1951.
62 61
63 The library also supports reading and writing files in gzip (.gz) format 62 The library also supports reading and writing files in gzip (.gz) format
64 with an interface similar to that of stdio using the functions that start 63 with an interface similar to that of stdio using the functions that start
65 with "gz". The gzip format is different from the zlib format. gzip is a 64 with "gz". The gzip format is different from the zlib format. gzip is a
66 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 65 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
67 66
68 This library can optionally read and write gzip streams in memory as well. 67 This library can optionally read and write gzip streams in memory as well.
69 68
70 The zlib format was designed to be compact and fast for use in memory 69 The zlib format was designed to be compact and fast for use in memory
71 and on communications channels. The gzip format was designed for single- 70 and on communications channels. The gzip format was designed for single-
72 file compression on file systems, has a larger header than zlib to maintain 71 file compression on file systems, has a larger header than zlib to maintain
73 directory information, and uses a different, slower check method than zlib. 72 directory information, and uses a different, slower check method than zlib.
74 73
75 The library does not install any signal handler. The decoder checks 74 The library does not install any signal handler. The decoder checks
76 the consistency of the compressed data, so the library should never 75 the consistency of the compressed data, so the library should never crash
77 crash even in case of corrupted input. 76 even in case of corrupted input.
78*/ 77*/
79 78
80typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 79typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
@@ -129,35 +128,34 @@ typedef struct gz_header_s {
129typedef gz_header FAR *gz_headerp; 128typedef gz_header FAR *gz_headerp;
130 129
131/* 130/*
132 The application must update next_in and avail_in when avail_in has 131 The application must update next_in and avail_in when avail_in has dropped
133 dropped to zero. It must update next_out and avail_out when avail_out 132 to zero. It must update next_out and avail_out when avail_out has dropped
134 has dropped to zero. The application must initialize zalloc, zfree and 133 to zero. The application must initialize zalloc, zfree and opaque before
135 opaque before calling the init function. All other fields are set by the 134 calling the init function. All other fields are set by the compression
136 compression library and must not be updated by the application. 135 library and must not be updated by the application.
137 136
138 The opaque value provided by the application will be passed as the first 137 The opaque value provided by the application will be passed as the first
139 parameter for calls of zalloc and zfree. This can be useful for custom 138 parameter for calls of zalloc and zfree. This can be useful for custom
140 memory management. The compression library attaches no meaning to the 139 memory management. The compression library attaches no meaning to the
141 opaque value. 140 opaque value.
142 141
143 zalloc must return Z_NULL if there is not enough memory for the object. 142 zalloc must return Z_NULL if there is not enough memory for the object.
144 If zlib is used in a multi-threaded application, zalloc and zfree must be 143 If zlib is used in a multi-threaded application, zalloc and zfree must be
145 thread safe. 144 thread safe.
146 145
147 On 16-bit systems, the functions zalloc and zfree must be able to allocate 146 On 16-bit systems, the functions zalloc and zfree must be able to allocate
148 exactly 65536 bytes, but will not be required to allocate more than this 147 exactly 65536 bytes, but will not be required to allocate more than this if
149 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 148 the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
150 pointers returned by zalloc for objects of exactly 65536 bytes *must* 149 returned by zalloc for objects of exactly 65536 bytes *must* have their
151 have their offset normalized to zero. The default allocation function 150 offset normalized to zero. The default allocation function provided by this
152 provided by this library ensures this (see zutil.c). To reduce memory 151 library ensures this (see zutil.c). To reduce memory requirements and avoid
153 requirements and avoid any allocation of 64K objects, at the expense of 152 any allocation of 64K objects, at the expense of compression ratio, compile
154 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 153 the library with -DMAX_WBITS=14 (see zconf.h).
155 154
156 The fields total_in and total_out can be used for statistics or 155 The fields total_in and total_out can be used for statistics or progress
157 progress reports. After compression, total_in holds the total size of 156 reports. After compression, total_in holds the total size of the
158 the uncompressed data and may be saved for use in the decompressor 157 uncompressed data and may be saved for use in the decompressor (particularly
159 (particularly if the decompressor wants to decompress everything in 158 if the decompressor wants to decompress everything in a single step).
160 a single step).
161*/ 159*/
162 160
163 /* constants */ 161 /* constants */
@@ -180,8 +178,8 @@ typedef gz_header FAR *gz_headerp;
180#define Z_MEM_ERROR (-4) 178#define Z_MEM_ERROR (-4)
181#define Z_BUF_ERROR (-5) 179#define Z_BUF_ERROR (-5)
182#define Z_VERSION_ERROR (-6) 180#define Z_VERSION_ERROR (-6)
183/* Return codes for the compression/decompression functions. Negative 181/* Return codes for the compression/decompression functions. Negative values
184 * values are errors, positive values are used for special but normal events. 182 * are errors, positive values are used for special but normal events.
185 */ 183 */
186 184
187#define Z_NO_COMPRESSION 0 185#define Z_NO_COMPRESSION 0
@@ -215,63 +213,63 @@ typedef gz_header FAR *gz_headerp;
215 213
216ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 214ZEXTERN const char * ZEXPORT zlibVersion OF((void));
217/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 215/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
218 If the first character differs, the library code actually used is 216 If the first character differs, the library code actually used is not
219 not compatible with the zlib.h header file used by the application. 217 compatible with the zlib.h header file used by the application. This check
220 This check is automatically made by deflateInit and inflateInit. 218 is automatically made by deflateInit and inflateInit.
221 */ 219 */
222 220
223/* 221/*
224ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 222ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
225 223
226 Initializes the internal stream state for compression. The fields 224 Initializes the internal stream state for compression. The fields
227 zalloc, zfree and opaque must be initialized before by the caller. 225 zalloc, zfree and opaque must be initialized before by the caller. If
228 If zalloc and zfree are set to Z_NULL, deflateInit updates them to 226 zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
229 use default allocation functions. 227 allocation functions.
230 228
231 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 229 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
232 1 gives best speed, 9 gives best compression, 0 gives no compression at 230 1 gives best speed, 9 gives best compression, 0 gives no compression at all
233 all (the input data is simply copied a block at a time). 231 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
234 Z_DEFAULT_COMPRESSION requests a default compromise between speed and 232 requests a default compromise between speed and compression (currently
235 compression (currently equivalent to level 6). 233 equivalent to level 6).
236 234
237 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 235 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
238 enough memory, Z_STREAM_ERROR if level is not a valid compression level, 236 enough memory, Z_STREAM_ERROR if level is not a valid compression level,
239 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 237 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
240 with the version assumed by the caller (ZLIB_VERSION). 238 with the version assumed by the caller (ZLIB_VERSION). msg is set to null
241 msg is set to null if there is no error message. deflateInit does not 239 if there is no error message. deflateInit does not perform any compression:
242 perform any compression: this will be done by deflate(). 240 this will be done by deflate().
243*/ 241*/
244 242
245 243
246ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 244ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
247/* 245/*
248 deflate compresses as much data as possible, and stops when the input 246 deflate compresses as much data as possible, and stops when the input
249 buffer becomes empty or the output buffer becomes full. It may introduce some 247 buffer becomes empty or the output buffer becomes full. It may introduce
250 output latency (reading input without producing any output) except when 248 some output latency (reading input without producing any output) except when
251 forced to flush. 249 forced to flush.
252 250
253 The detailed semantics are as follows. deflate performs one or both of the 251 The detailed semantics are as follows. deflate performs one or both of the
254 following actions: 252 following actions:
255 253
256 - Compress more input starting at next_in and update next_in and avail_in 254 - Compress more input starting at next_in and update next_in and avail_in
257 accordingly. If not all input can be processed (because there is not 255 accordingly. If not all input can be processed (because there is not
258 enough room in the output buffer), next_in and avail_in are updated and 256 enough room in the output buffer), next_in and avail_in are updated and
259 processing will resume at this point for the next call of deflate(). 257 processing will resume at this point for the next call of deflate().
260 258
261 - Provide more output starting at next_out and update next_out and avail_out 259 - Provide more output starting at next_out and update next_out and avail_out
262 accordingly. This action is forced if the parameter flush is non zero. 260 accordingly. This action is forced if the parameter flush is non zero.
263 Forcing flush frequently degrades the compression ratio, so this parameter 261 Forcing flush frequently degrades the compression ratio, so this parameter
264 should be set only when necessary (in interactive applications). 262 should be set only when necessary (in interactive applications). Some
265 Some output may be provided even if flush is not set. 263 output may be provided even if flush is not set.
266 264
267 Before the call of deflate(), the application should ensure that at least 265 Before the call of deflate(), the application should ensure that at least
268 one of the actions is possible, by providing more input and/or consuming 266 one of the actions is possible, by providing more input and/or consuming more
269 more output, and updating avail_in or avail_out accordingly; avail_out 267 output, and updating avail_in or avail_out accordingly; avail_out should
270 should never be zero before the call. The application can consume the 268 never be zero before the call. The application can consume the compressed
271 compressed output when it wants, for example when the output buffer is full 269 output when it wants, for example when the output buffer is full (avail_out
272 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 270 == 0), or after each call of deflate(). If deflate returns Z_OK and with
273 and with zero avail_out, it must be called again after making room in the 271 zero avail_out, it must be called again after making room in the output
274 output buffer because there might be more output pending. 272 buffer because there might be more output pending.
275 273
276 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 274 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
277 decide how much data to accumulate before producing output, in order to 275 decide how much data to accumulate before producing output, in order to
@@ -279,12 +277,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
279 277
280 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 278 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
281 flushed to the output buffer and the output is aligned on a byte boundary, so 279 flushed to the output buffer and the output is aligned on a byte boundary, so
282 that the decompressor can get all input data available so far. (In particular 280 that the decompressor can get all input data available so far. (In
283 avail_in is zero after the call if enough output space has been provided 281 particular avail_in is zero after the call if enough output space has been
284 before the call.) Flushing may degrade compression for some compression 282 provided before the call.) Flushing may degrade compression for some
285 algorithms and so it should be used only when necessary. This completes the 283 compression algorithms and so it should be used only when necessary. This
286 current deflate block and follows it with an empty stored block that is three 284 completes the current deflate block and follows it with an empty stored block
287 bits plus filler bits to the next byte, followed by four bytes (00 00 ff ff). 285 that is three bits plus filler bits to the next byte, followed by four bytes
286 (00 00 ff ff).
288 287
289 If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the 288 If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
290 output buffer, but the output is not aligned to a byte boundary. All of the 289 output buffer, but the output is not aligned to a byte boundary. All of the
@@ -306,43 +305,43 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
306 If flush is set to Z_FULL_FLUSH, all output is flushed as with 305 If flush is set to Z_FULL_FLUSH, all output is flushed as with
307 Z_SYNC_FLUSH, and the compression state is reset so that decompression can 306 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
308 restart from this point if previous compressed data has been damaged or if 307 restart from this point if previous compressed data has been damaged or if
309 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 308 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
310 compression. 309 compression.
311 310
312 If deflate returns with avail_out == 0, this function must be called again 311 If deflate returns with avail_out == 0, this function must be called again
313 with the same value of the flush parameter and more output space (updated 312 with the same value of the flush parameter and more output space (updated
314 avail_out), until the flush is complete (deflate returns with non-zero 313 avail_out), until the flush is complete (deflate returns with non-zero
315 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 314 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
316 avail_out is greater than six to avoid repeated flush markers due to 315 avail_out is greater than six to avoid repeated flush markers due to
317 avail_out == 0 on return. 316 avail_out == 0 on return.
318 317
319 If the parameter flush is set to Z_FINISH, pending input is processed, 318 If the parameter flush is set to Z_FINISH, pending input is processed,
320 pending output is flushed and deflate returns with Z_STREAM_END if there 319 pending output is flushed and deflate returns with Z_STREAM_END if there was
321 was enough output space; if deflate returns with Z_OK, this function must be 320 enough output space; if deflate returns with Z_OK, this function must be
322 called again with Z_FINISH and more output space (updated avail_out) but no 321 called again with Z_FINISH and more output space (updated avail_out) but no
323 more input data, until it returns with Z_STREAM_END or an error. After 322 more input data, until it returns with Z_STREAM_END or an error. After
324 deflate has returned Z_STREAM_END, the only possible operations on the 323 deflate has returned Z_STREAM_END, the only possible operations on the stream
325 stream are deflateReset or deflateEnd. 324 are deflateReset or deflateEnd.
326 325
327 Z_FINISH can be used immediately after deflateInit if all the compression 326 Z_FINISH can be used immediately after deflateInit if all the compression
328 is to be done in a single step. In this case, avail_out must be at least 327 is to be done in a single step. In this case, avail_out must be at least the
329 the value returned by deflateBound (see below). If deflate does not return 328 value returned by deflateBound (see below). If deflate does not return
330 Z_STREAM_END, then it must be called again as described above. 329 Z_STREAM_END, then it must be called again as described above.
331 330
332 deflate() sets strm->adler to the adler32 checksum of all input read 331 deflate() sets strm->adler to the adler32 checksum of all input read
333 so far (that is, total_in bytes). 332 so far (that is, total_in bytes).
334 333
335 deflate() may update strm->data_type if it can make a good guess about 334 deflate() may update strm->data_type if it can make a good guess about
336 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 335 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
337 binary. This field is only for information purposes and does not affect 336 binary. This field is only for information purposes and does not affect the
338 the compression algorithm in any manner. 337 compression algorithm in any manner.
339 338
340 deflate() returns Z_OK if some progress has been made (more input 339 deflate() returns Z_OK if some progress has been made (more input
341 processed or more output produced), Z_STREAM_END if all input has been 340 processed or more output produced), Z_STREAM_END if all input has been
342 consumed and all output has been produced (only when flush is set to 341 consumed and all output has been produced (only when flush is set to
343 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 342 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
344 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible 343 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
345 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 344 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
346 fatal, and deflate() can be called again with more input and more output 345 fatal, and deflate() can be called again with more input and more output
347 space to continue compressing. 346 space to continue compressing.
348*/ 347*/
@@ -351,13 +350,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
351ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 350ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
352/* 351/*
353 All dynamically allocated data structures for this stream are freed. 352 All dynamically allocated data structures for this stream are freed.
354 This function discards any unprocessed input and does not flush any 353 This function discards any unprocessed input and does not flush any pending
355 pending output. 354 output.
356 355
357 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 356 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
358 stream state was inconsistent, Z_DATA_ERROR if the stream was freed 357 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
359 prematurely (some input or output was discarded). In the error case, 358 prematurely (some input or output was discarded). In the error case, msg
360 msg may be set but then points to a static string (which must not be 359 may be set but then points to a static string (which must not be
361 deallocated). 360 deallocated).
362*/ 361*/
363 362
@@ -365,10 +364,10 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
365/* 364/*
366ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 365ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
367 366
368 Initializes the internal stream state for decompression. The fields 367 Initializes the internal stream state for decompression. The fields
369 next_in, avail_in, zalloc, zfree and opaque must be initialized before by 368 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
370 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 369 the caller. If next_in is not Z_NULL and avail_in is large enough (the
371 value depends on the compression method), inflateInit determines the 370 exact value depends on the compression method), inflateInit determines the
372 compression method from the zlib header and allocates all data structures 371 compression method from the zlib header and allocates all data structures
373 accordingly; otherwise the allocation will be deferred to the first call of 372 accordingly; otherwise the allocation will be deferred to the first call of
374 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 373 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
@@ -378,66 +377,66 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
378 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 377 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
379 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 378 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
380 invalid, such as a null pointer to the structure. msg is set to null if 379 invalid, such as a null pointer to the structure. msg is set to null if
381 there is no error message. inflateInit does not perform any decompression 380 there is no error message. inflateInit does not perform any decompression
382 apart from possibly reading the zlib header if present: actual decompression 381 apart from possibly reading the zlib header if present: actual decompression
383 will be done by inflate(). (So next_in and avail_in may be modified, but 382 will be done by inflate(). (So next_in and avail_in may be modified, but
384 next_out and avail_out are unused and unchanged.) The current 383 next_out and avail_out are unused and unchanged.) The current implementation
385 implementation of inflateInit() does not process any header information -- 384 of inflateInit() does not process any header information -- that is deferred
386 that is deferred until inflate() is called. 385 until inflate() is called.
387*/ 386*/
388 387
389 388
390ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 389ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
391/* 390/*
392 inflate decompresses as much data as possible, and stops when the input 391 inflate decompresses as much data as possible, and stops when the input
393 buffer becomes empty or the output buffer becomes full. It may introduce 392 buffer becomes empty or the output buffer becomes full. It may introduce
394 some output latency (reading input without producing any output) except when 393 some output latency (reading input without producing any output) except when
395 forced to flush. 394 forced to flush.
396 395
397 The detailed semantics are as follows. inflate performs one or both of the 396 The detailed semantics are as follows. inflate performs one or both of the
398 following actions: 397 following actions:
399 398
400 - Decompress more input starting at next_in and update next_in and avail_in 399 - Decompress more input starting at next_in and update next_in and avail_in
401 accordingly. If not all input can be processed (because there is not 400 accordingly. If not all input can be processed (because there is not
402 enough room in the output buffer), next_in is updated and processing 401 enough room in the output buffer), next_in is updated and processing will
403 will resume at this point for the next call of inflate(). 402 resume at this point for the next call of inflate().
404 403
405 - Provide more output starting at next_out and update next_out and avail_out 404 - Provide more output starting at next_out and update next_out and avail_out
406 accordingly. inflate() provides as much output as possible, until there 405 accordingly. inflate() provides as much output as possible, until there is
407 is no more input data or no more space in the output buffer (see below 406 no more input data or no more space in the output buffer (see below about
408 about the flush parameter). 407 the flush parameter).
409 408
410 Before the call of inflate(), the application should ensure that at least 409 Before the call of inflate(), the application should ensure that at least
411 one of the actions is possible, by providing more input and/or consuming 410 one of the actions is possible, by providing more input and/or consuming more
412 more output, and updating the next_* and avail_* values accordingly. 411 output, and updating the next_* and avail_* values accordingly. The
413 The application can consume the uncompressed output when it wants, for 412 application can consume the uncompressed output when it wants, for example
414 example when the output buffer is full (avail_out == 0), or after each 413 when the output buffer is full (avail_out == 0), or after each call of
415 call of inflate(). If inflate returns Z_OK and with zero avail_out, it 414 inflate(). If inflate returns Z_OK and with zero avail_out, it must be
416 must be called again after making room in the output buffer because there 415 called again after making room in the output buffer because there might be
417 might be more output pending. 416 more output pending.
418 417
419 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, 418 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
420 Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much 419 Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
421 output as possible to the output buffer. Z_BLOCK requests that inflate() stop 420 output as possible to the output buffer. Z_BLOCK requests that inflate()
422 if and when it gets to the next deflate block boundary. When decoding the 421 stop if and when it gets to the next deflate block boundary. When decoding
423 zlib or gzip format, this will cause inflate() to return immediately after 422 the zlib or gzip format, this will cause inflate() to return immediately
424 the header and before the first block. When doing a raw inflate, inflate() 423 after the header and before the first block. When doing a raw inflate,
425 will go ahead and process the first block, and will return when it gets to 424 inflate() will go ahead and process the first block, and will return when it
426 the end of that block, or when it runs out of data. 425 gets to the end of that block, or when it runs out of data.
427 426
428 The Z_BLOCK option assists in appending to or combining deflate streams. 427 The Z_BLOCK option assists in appending to or combining deflate streams.
429 Also to assist in this, on return inflate() will set strm->data_type to the 428 Also to assist in this, on return inflate() will set strm->data_type to the
430 number of unused bits in the last byte taken from strm->next_in, plus 64 429 number of unused bits in the last byte taken from strm->next_in, plus 64 if
431 if inflate() is currently decoding the last block in the deflate stream, 430 inflate() is currently decoding the last block in the deflate stream, plus
432 plus 128 if inflate() returned immediately after decoding an end-of-block 431 128 if inflate() returned immediately after decoding an end-of-block code or
433 code or decoding the complete header up to just before the first byte of the 432 decoding the complete header up to just before the first byte of the deflate
434 deflate stream. The end-of-block will not be indicated until all of the 433 stream. The end-of-block will not be indicated until all of the uncompressed
435 uncompressed data from that block has been written to strm->next_out. The 434 data from that block has been written to strm->next_out. The number of
436 number of unused bits may in general be greater than seven, except when 435 unused bits may in general be greater than seven, except when bit 7 of
437 bit 7 of data_type is set, in which case the number of unused bits will be 436 data_type is set, in which case the number of unused bits will be less than
438 less than eight. data_type is set as noted here every time inflate() 437 eight. data_type is set as noted here every time inflate() returns for all
439 returns for all flush options, and so can be used to determine the amount 438 flush options, and so can be used to determine the amount of currently
440 of currently consumed input in bits. 439 consumed input in bits.
441 440
442 The Z_TREES option behaves as Z_BLOCK does, but it also returns when the 441 The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
443 end of each deflate block header is reached, before any actual data in that 442 end of each deflate block header is reached, before any actual data in that
@@ -447,19 +446,19 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
447 immediately after reaching the end of the deflate block header. 446 immediately after reaching the end of the deflate block header.
448 447
449 inflate() should normally be called until it returns Z_STREAM_END or an 448 inflate() should normally be called until it returns Z_STREAM_END or an
450 error. However if all decompression is to be performed in a single step 449 error. However if all decompression is to be performed in a single step (a
451 (a single call of inflate), the parameter flush should be set to 450 single call of inflate), the parameter flush should be set to Z_FINISH. In
452 Z_FINISH. In this case all pending input is processed and all pending 451 this case all pending input is processed and all pending output is flushed;
453 output is flushed; avail_out must be large enough to hold all the 452 avail_out must be large enough to hold all the uncompressed data. (The size
454 uncompressed data. (The size of the uncompressed data may have been saved 453 of the uncompressed data may have been saved by the compressor for this
455 by the compressor for this purpose.) The next operation on this stream must 454 purpose.) The next operation on this stream must be inflateEnd to deallocate
456 be inflateEnd to deallocate the decompression state. The use of Z_FINISH 455 the decompression state. The use of Z_FINISH is never required, but can be
457 is never required, but can be used to inform inflate that a faster approach 456 used to inform inflate that a faster approach may be used for the single
458 may be used for the single inflate() call. 457 inflate() call.
459 458
460 In this implementation, inflate() always flushes as much output as 459 In this implementation, inflate() always flushes as much output as
461 possible to the output buffer, and always uses the faster approach on the 460 possible to the output buffer, and always uses the faster approach on the
462 first call. So the only effect of the flush parameter in this implementation 461 first call. So the only effect of the flush parameter in this implementation
463 is on the return value of inflate(), as noted below, or when it returns early 462 is on the return value of inflate(), as noted below, or when it returns early
464 because Z_BLOCK or Z_TREES is used. 463 because Z_BLOCK or Z_TREES is used.
465 464
@@ -468,7 +467,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
468 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 467 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
469 strm->adler to the adler32 checksum of all output produced so far (that is, 468 strm->adler to the adler32 checksum of all output produced so far (that is,
470 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 469 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
471 below. At the end of the stream, inflate() checks that its computed adler32 470 below. At the end of the stream, inflate() checks that its computed adler32
472 checksum is equal to that saved by the compressor and returns Z_STREAM_END 471 checksum is equal to that saved by the compressor and returns Z_STREAM_END
473 only if the checksum is correct. 472 only if the checksum is correct.
474 473
@@ -487,22 +486,22 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
487 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 486 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
488 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, 487 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
489 Z_BUF_ERROR if no progress is possible or if there was not enough room in the 488 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
490 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 489 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
491 inflate() can be called again with more input and more output space to 490 inflate() can be called again with more input and more output space to
492 continue decompressing. If Z_DATA_ERROR is returned, the application may then 491 continue decompressing. If Z_DATA_ERROR is returned, the application may
493 call inflateSync() to look for a good compression block if a partial recovery 492 then call inflateSync() to look for a good compression block if a partial
494 of the data is desired. 493 recovery of the data is desired.
495*/ 494*/
496 495
497 496
498ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 497ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
499/* 498/*
500 All dynamically allocated data structures for this stream are freed. 499 All dynamically allocated data structures for this stream are freed.
501 This function discards any unprocessed input and does not flush any 500 This function discards any unprocessed input and does not flush any pending
502 pending output. 501 output.
503 502
504 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 503 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
505 was inconsistent. In the error case, msg may be set but then points to a 504 was inconsistent. In the error case, msg may be set but then points to a
506 static string (which must not be deallocated). 505 static string (which must not be deallocated).
507*/ 506*/
508 507
@@ -520,55 +519,55 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
520 int memLevel, 519 int memLevel,
521 int strategy)); 520 int strategy));
522 521
523 This is another version of deflateInit with more compression options. The 522 This is another version of deflateInit with more compression options. The
524 fields next_in, zalloc, zfree and opaque must be initialized before by 523 fields next_in, zalloc, zfree and opaque must be initialized before by the
525 the caller. 524 caller.
526 525
527 The method parameter is the compression method. It must be Z_DEFLATED in 526 The method parameter is the compression method. It must be Z_DEFLATED in
528 this version of the library. 527 this version of the library.
529 528
530 The windowBits parameter is the base two logarithm of the window size 529 The windowBits parameter is the base two logarithm of the window size
531 (the size of the history buffer). It should be in the range 8..15 for this 530 (the size of the history buffer). It should be in the range 8..15 for this
532 version of the library. Larger values of this parameter result in better 531 version of the library. Larger values of this parameter result in better
533 compression at the expense of memory usage. The default value is 15 if 532 compression at the expense of memory usage. The default value is 15 if
534 deflateInit is used instead. 533 deflateInit is used instead.
535 534
536 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 535 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
537 determines the window size. deflate() will then generate raw deflate data 536 determines the window size. deflate() will then generate raw deflate data
538 with no zlib header or trailer, and will not compute an adler32 check value. 537 with no zlib header or trailer, and will not compute an adler32 check value.
539 538
540 windowBits can also be greater than 15 for optional gzip encoding. Add 539 windowBits can also be greater than 15 for optional gzip encoding. Add
541 16 to windowBits to write a simple gzip header and trailer around the 540 16 to windowBits to write a simple gzip header and trailer around the
542 compressed data instead of a zlib wrapper. The gzip header will have no 541 compressed data instead of a zlib wrapper. The gzip header will have no
543 file name, no extra data, no comment, no modification time (set to zero), 542 file name, no extra data, no comment, no modification time (set to zero), no
544 no header crc, and the operating system will be set to 255 (unknown). If a 543 header crc, and the operating system will be set to 255 (unknown). If a
545 gzip stream is being written, strm->adler is a crc32 instead of an adler32. 544 gzip stream is being written, strm->adler is a crc32 instead of an adler32.
546 545
547 The memLevel parameter specifies how much memory should be allocated 546 The memLevel parameter specifies how much memory should be allocated
548 for the internal compression state. memLevel=1 uses minimum memory but 547 for the internal compression state. memLevel=1 uses minimum memory but is
549 is slow and reduces compression ratio; memLevel=9 uses maximum memory 548 slow and reduces compression ratio; memLevel=9 uses maximum memory for
550 for optimal speed. The default value is 8. See zconf.h for total memory 549 optimal speed. The default value is 8. See zconf.h for total memory usage
551 usage as a function of windowBits and memLevel. 550 as a function of windowBits and memLevel.
552 551
553 The strategy parameter is used to tune the compression algorithm. Use the 552 The strategy parameter is used to tune the compression algorithm. Use the
554 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 553 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
555 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 554 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
556 string match), or Z_RLE to limit match distances to one (run-length 555 string match), or Z_RLE to limit match distances to one (run-length
557 encoding). Filtered data consists mostly of small values with a somewhat 556 encoding). Filtered data consists mostly of small values with a somewhat
558 random distribution. In this case, the compression algorithm is tuned to 557 random distribution. In this case, the compression algorithm is tuned to
559 compress them better. The effect of Z_FILTERED is to force more Huffman 558 compress them better. The effect of Z_FILTERED is to force more Huffman
560 coding and less string matching; it is somewhat intermediate between 559 coding and less string matching; it is somewhat intermediate between
561 Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as 560 Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
562 fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The 561 fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
563 strategy parameter only affects the compression ratio but not the 562 strategy parameter only affects the compression ratio but not the
564 correctness of the compressed output even if it is not set appropriately. 563 correctness of the compressed output even if it is not set appropriately.
565 Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler 564 Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
566 decoder for special applications. 565 decoder for special applications.
567 566
568 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 567 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
569 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 568 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
570 method). msg is set to null if there is no error message. deflateInit2 does 569 method). msg is set to null if there is no error message. deflateInit2
571 not perform any compression: this will be done by deflate(). 570 does not perform any compression: this will be done by deflate().
572*/ 571*/
573 572
574ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 573ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
@@ -576,14 +575,14 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
576 uInt dictLength)); 575 uInt dictLength));
577/* 576/*
578 Initializes the compression dictionary from the given byte sequence 577 Initializes the compression dictionary from the given byte sequence
579 without producing any compressed output. This function must be called 578 without producing any compressed output. This function must be called
580 immediately after deflateInit, deflateInit2 or deflateReset, before any 579 immediately after deflateInit, deflateInit2 or deflateReset, before any call
581 call of deflate. The compressor and decompressor must use exactly the same 580 of deflate. The compressor and decompressor must use exactly the same
582 dictionary (see inflateSetDictionary). 581 dictionary (see inflateSetDictionary).
583 582
584 The dictionary should consist of strings (byte sequences) that are likely 583 The dictionary should consist of strings (byte sequences) that are likely
585 to be encountered later in the data to be compressed, with the most commonly 584 to be encountered later in the data to be compressed, with the most commonly
586 used strings preferably put towards the end of the dictionary. Using a 585 used strings preferably put towards the end of the dictionary. Using a
587 dictionary is most useful when the data to be compressed is short and can be 586 dictionary is most useful when the data to be compressed is short and can be
588 predicted with good accuracy; the data can then be compressed better than 587 predicted with good accuracy; the data can then be compressed better than
589 with the default empty dictionary. 588 with the default empty dictionary.
@@ -591,22 +590,22 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
591 Depending on the size of the compression data structures selected by 590 Depending on the size of the compression data structures selected by
592 deflateInit or deflateInit2, a part of the dictionary may in effect be 591 deflateInit or deflateInit2, a part of the dictionary may in effect be
593 discarded, for example if the dictionary is larger than the window size 592 discarded, for example if the dictionary is larger than the window size
594 provided in deflateInit or deflateInit2. Thus the strings most likely to be 593 provided in deflateInit or deflateInit2. Thus the strings most likely to be
595 useful should be put at the end of the dictionary, not at the front. In 594 useful should be put at the end of the dictionary, not at the front. In
596 addition, the current implementation of deflate will use at most the window 595 addition, the current implementation of deflate will use at most the window
597 size minus 262 bytes of the provided dictionary. 596 size minus 262 bytes of the provided dictionary.
598 597
599 Upon return of this function, strm->adler is set to the adler32 value 598 Upon return of this function, strm->adler is set to the adler32 value
600 of the dictionary; the decompressor may later use this value to determine 599 of the dictionary; the decompressor may later use this value to determine
601 which dictionary has been used by the compressor. (The adler32 value 600 which dictionary has been used by the compressor. (The adler32 value
602 applies to the whole dictionary even if only a subset of the dictionary is 601 applies to the whole dictionary even if only a subset of the dictionary is
603 actually used by the compressor.) If a raw deflate was requested, then the 602 actually used by the compressor.) If a raw deflate was requested, then the
604 adler32 value is not computed and strm->adler is not set. 603 adler32 value is not computed and strm->adler is not set.
605 604
606 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 605 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
607 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 606 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
608 inconsistent (for example if deflate has already been called for this stream 607 inconsistent (for example if deflate has already been called for this stream
609 or if the compression method is bsort). deflateSetDictionary does not 608 or if the compression method is bsort). deflateSetDictionary does not
610 perform any compression: this will be done by deflate(). 609 perform any compression: this will be done by deflate().
611*/ 610*/
612 611
@@ -617,25 +616,25 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
617 616
618 This function can be useful when several compression strategies will be 617 This function can be useful when several compression strategies will be
619 tried, for example when there are several ways of pre-processing the input 618 tried, for example when there are several ways of pre-processing the input
620 data with a filter. The streams that will be discarded should then be freed 619 data with a filter. The streams that will be discarded should then be freed
621 by calling deflateEnd. Note that deflateCopy duplicates the internal 620 by calling deflateEnd. Note that deflateCopy duplicates the internal
622 compression state which can be quite large, so this strategy is slow and 621 compression state which can be quite large, so this strategy is slow and can
623 can consume lots of memory. 622 consume lots of memory.
624 623
625 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 624 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
626 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 625 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
627 (such as zalloc being Z_NULL). msg is left unchanged in both source and 626 (such as zalloc being Z_NULL). msg is left unchanged in both source and
628 destination. 627 destination.
629*/ 628*/
630 629
631ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 630ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
632/* 631/*
633 This function is equivalent to deflateEnd followed by deflateInit, 632 This function is equivalent to deflateEnd followed by deflateInit,
634 but does not free and reallocate all the internal compression state. 633 but does not free and reallocate all the internal compression state. The
635 The stream will keep the same compression level and any other attributes 634 stream will keep the same compression level and any other attributes that
636 that may have been set by deflateInit2. 635 may have been set by deflateInit2.
637 636
638 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 637 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
639 stream state was inconsistent (such as zalloc or state being Z_NULL). 638 stream state was inconsistent (such as zalloc or state being Z_NULL).
640*/ 639*/
641 640
@@ -646,18 +645,18 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
646 Dynamically update the compression level and compression strategy. The 645 Dynamically update the compression level and compression strategy. The
647 interpretation of level and strategy is as in deflateInit2. This can be 646 interpretation of level and strategy is as in deflateInit2. This can be
648 used to switch between compression and straight copy of the input data, or 647 used to switch between compression and straight copy of the input data, or
649 to switch to a different kind of input data requiring a different 648 to switch to a different kind of input data requiring a different strategy.
650 strategy. If the compression level is changed, the input available so far 649 If the compression level is changed, the input available so far is
651 is compressed with the old level (and may be flushed); the new level will 650 compressed with the old level (and may be flushed); the new level will take
652 take effect only at the next call of deflate(). 651 effect only at the next call of deflate().
653 652
654 Before the call of deflateParams, the stream state must be set as for 653 Before the call of deflateParams, the stream state must be set as for
655 a call of deflate(), since the currently available input may have to 654 a call of deflate(), since the currently available input may have to be
656 be compressed and flushed. In particular, strm->avail_out must be non-zero. 655 compressed and flushed. In particular, strm->avail_out must be non-zero.
657 656
658 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 657 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
659 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 658 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
660 if strm->avail_out was zero. 659 strm->avail_out was zero.
661*/ 660*/
662 661
663ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 662ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
@@ -692,21 +691,21 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
692 int value)); 691 int value));
693/* 692/*
694 deflatePrime() inserts bits in the deflate output stream. The intent 693 deflatePrime() inserts bits in the deflate output stream. The intent
695 is that this function is used to start off the deflate output with the 694 is that this function is used to start off the deflate output with the bits
696 bits leftover from a previous deflate stream when appending to it. As such, 695 leftover from a previous deflate stream when appending to it. As such, this
697 this function can only be used for raw deflate, and must be used before the 696 function can only be used for raw deflate, and must be used before the first
698 first deflate() call after a deflateInit2() or deflateReset(). bits must be 697 deflate() call after a deflateInit2() or deflateReset(). bits must be less
699 less than or equal to 16, and that many of the least significant bits of 698 than or equal to 16, and that many of the least significant bits of value
700 value will be inserted in the output. 699 will be inserted in the output.
701 700
702 deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 701 deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
703 stream state was inconsistent. 702 stream state was inconsistent.
704*/ 703*/
705 704
706ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 705ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
707 gz_headerp head)); 706 gz_headerp head));
708/* 707/*
709 deflateSetHeader() provides gzip header information for when a gzip 708 deflateSetHeader() provides gzip header information for when a gzip
710 stream is requested by deflateInit2(). deflateSetHeader() may be called 709 stream is requested by deflateInit2(). deflateSetHeader() may be called
711 after deflateInit2() or deflateReset() and before the first call of 710 after deflateInit2() or deflateReset() and before the first call of
712 deflate(). The text, time, os, extra field, name, and comment information 711 deflate(). The text, time, os, extra field, name, and comment information
@@ -719,11 +718,11 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
719 1.3.x) do not support header crc's, and will report that it is a "multi-part 718 1.3.x) do not support header crc's, and will report that it is a "multi-part
720 gzip file" and give up. 719 gzip file" and give up.
721 720
722 If deflateSetHeader is not used, the default gzip header has text false, 721 If deflateSetHeader is not used, the default gzip header has text false,
723 the time set to zero, and os set to 255, with no extra, name, or comment 722 the time set to zero, and os set to 255, with no extra, name, or comment
724 fields. The gzip header is returned to the default state by deflateReset(). 723 fields. The gzip header is returned to the default state by deflateReset().
725 724
726 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 725 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
727 stream state was inconsistent. 726 stream state was inconsistent.
728*/ 727*/
729 728
@@ -731,50 +730,50 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
731ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 730ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
732 int windowBits)); 731 int windowBits));
733 732
734 This is another version of inflateInit with an extra parameter. The 733 This is another version of inflateInit with an extra parameter. The
735 fields next_in, avail_in, zalloc, zfree and opaque must be initialized 734 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
736 before by the caller. 735 before by the caller.
737 736
738 The windowBits parameter is the base two logarithm of the maximum window 737 The windowBits parameter is the base two logarithm of the maximum window
739 size (the size of the history buffer). It should be in the range 8..15 for 738 size (the size of the history buffer). It should be in the range 8..15 for
740 this version of the library. The default value is 15 if inflateInit is used 739 this version of the library. The default value is 15 if inflateInit is used
741 instead. windowBits must be greater than or equal to the windowBits value 740 instead. windowBits must be greater than or equal to the windowBits value
742 provided to deflateInit2() while compressing, or it must be equal to 15 if 741 provided to deflateInit2() while compressing, or it must be equal to 15 if
743 deflateInit2() was not used. If a compressed stream with a larger window 742 deflateInit2() was not used. If a compressed stream with a larger window
744 size is given as input, inflate() will return with the error code 743 size is given as input, inflate() will return with the error code
745 Z_DATA_ERROR instead of trying to allocate a larger window. 744 Z_DATA_ERROR instead of trying to allocate a larger window.
746 745
747 windowBits can also be zero to request that inflate use the window size in 746 windowBits can also be zero to request that inflate use the window size in
748 the zlib header of the compressed stream. 747 the zlib header of the compressed stream.
749 748
750 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 749 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
751 determines the window size. inflate() will then process raw deflate data, 750 determines the window size. inflate() will then process raw deflate data,
752 not looking for a zlib or gzip header, not generating a check value, and not 751 not looking for a zlib or gzip header, not generating a check value, and not
753 looking for any check values for comparison at the end of the stream. This 752 looking for any check values for comparison at the end of the stream. This
754 is for use with other formats that use the deflate compressed data format 753 is for use with other formats that use the deflate compressed data format
755 such as zip. Those formats provide their own check values. If a custom 754 such as zip. Those formats provide their own check values. If a custom
756 format is developed using the raw deflate format for compressed data, it is 755 format is developed using the raw deflate format for compressed data, it is
757 recommended that a check value such as an adler32 or a crc32 be applied to 756 recommended that a check value such as an adler32 or a crc32 be applied to
758 the uncompressed data as is done in the zlib, gzip, and zip formats. For 757 the uncompressed data as is done in the zlib, gzip, and zip formats. For
759 most applications, the zlib format should be used as is. Note that comments 758 most applications, the zlib format should be used as is. Note that comments
760 above on the use in deflateInit2() applies to the magnitude of windowBits. 759 above on the use in deflateInit2() applies to the magnitude of windowBits.
761 760
762 windowBits can also be greater than 15 for optional gzip decoding. Add 761 windowBits can also be greater than 15 for optional gzip decoding. Add
763 32 to windowBits to enable zlib and gzip decoding with automatic header 762 32 to windowBits to enable zlib and gzip decoding with automatic header
764 detection, or add 16 to decode only the gzip format (the zlib format will 763 detection, or add 16 to decode only the gzip format (the zlib format will
765 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 764 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
766 a crc32 instead of an adler32. 765 crc32 instead of an adler32.
767 766
768 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 767 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
769 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 768 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
770 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 769 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
771 invalid, such as a null pointer to the structure. msg is set to null if 770 invalid, such as a null pointer to the structure. msg is set to null if
772 there is no error message. inflateInit2 does not perform any decompression 771 there is no error message. inflateInit2 does not perform any decompression
773 apart from possibly reading the zlib header if present: actual decompression 772 apart from possibly reading the zlib header if present: actual decompression
774 will be done by inflate(). (So next_in and avail_in may be modified, but 773 will be done by inflate(). (So next_in and avail_in may be modified, but
775 next_out and avail_out are unused and unchanged.) The current 774 next_out and avail_out are unused and unchanged.) The current implementation
776 implementation of inflateInit2() does not process any header information -- 775 of inflateInit2() does not process any header information -- that is
777 that is deferred until inflate() is called. 776 deferred until inflate() is called.
778*/ 777*/
779 778
780ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 779ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
@@ -782,8 +781,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
782 uInt dictLength)); 781 uInt dictLength));
783/* 782/*
784 Initializes the decompression dictionary from the given uncompressed byte 783 Initializes the decompression dictionary from the given uncompressed byte
785 sequence. This function must be called immediately after a call of inflate, 784 sequence. This function must be called immediately after a call of inflate,
786 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 785 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
787 can be determined from the adler32 value returned by that call of inflate. 786 can be determined from the adler32 value returned by that call of inflate.
788 The compressor and decompressor must use exactly the same dictionary (see 787 The compressor and decompressor must use exactly the same dictionary (see
789 deflateSetDictionary). For raw inflate, this function can be called 788 deflateSetDictionary). For raw inflate, this function can be called
@@ -792,26 +791,26 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
792 dictionary that was used for compression is provided. 791 dictionary that was used for compression is provided.
793 792
794 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 793 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
795 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 794 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
796 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 795 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
797 expected one (incorrect adler32 value). inflateSetDictionary does not 796 expected one (incorrect adler32 value). inflateSetDictionary does not
798 perform any decompression: this will be done by subsequent calls of 797 perform any decompression: this will be done by subsequent calls of
799 inflate(). 798 inflate().
800*/ 799*/
801 800
802ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 801ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
803/* 802/*
804 Skips invalid compressed data until a full flush point (see above the 803 Skips invalid compressed data until a full flush point (see above the
805 description of deflate with Z_FULL_FLUSH) can be found, or until all 804 description of deflate with Z_FULL_FLUSH) can be found, or until all
806 available input is skipped. No output is provided. 805 available input is skipped. No output is provided.
807 806
808 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 807 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
809 if no more input was provided, Z_DATA_ERROR if no flush point has been found, 808 if no more input was provided, Z_DATA_ERROR if no flush point has been
810 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 809 found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
811 case, the application may save the current current value of total_in which 810 success case, the application may save the current current value of total_in
812 indicates where valid compressed data was found. In the error case, the 811 which indicates where valid compressed data was found. In the error case,
813 application may repeatedly call inflateSync, providing more input each time, 812 the application may repeatedly call inflateSync, providing more input each
814 until success or end of the input data. 813 time, until success or end of the input data.
815*/ 814*/
816 815
817ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 816ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
@@ -826,17 +825,17 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
826 825
827 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 826 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
828 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 827 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
829 (such as zalloc being Z_NULL). msg is left unchanged in both source and 828 (such as zalloc being Z_NULL). msg is left unchanged in both source and
830 destination. 829 destination.
831*/ 830*/
832 831
833ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 832ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
834/* 833/*
835 This function is equivalent to inflateEnd followed by inflateInit, 834 This function is equivalent to inflateEnd followed by inflateInit,
836 but does not free and reallocate all the internal decompression state. 835 but does not free and reallocate all the internal decompression state. The
837 The stream will keep attributes that may have been set by inflateInit2. 836 stream will keep attributes that may have been set by inflateInit2.
838 837
839 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 838 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
840 stream state was inconsistent (such as zalloc or state being Z_NULL). 839 stream state was inconsistent (such as zalloc or state being Z_NULL).
841*/ 840*/
842 841
@@ -844,10 +843,10 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
844 int windowBits)); 843 int windowBits));
845/* 844/*
846 This function is the same as inflateReset, but it also permits changing 845 This function is the same as inflateReset, but it also permits changing
847 the wrap and window size requests. The windowBits parameter is 846 the wrap and window size requests. The windowBits parameter is interpreted
848 interpreted the same as it is for inflateInit2. 847 the same as it is for inflateInit2.
849 848
850 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 849 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
851 stream state was inconsistent (such as zalloc or state being Z_NULL), or if 850 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
852 the windowBits parameter is invalid. 851 the windowBits parameter is invalid.
853*/ 852*/
@@ -857,19 +856,19 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
857 int value)); 856 int value));
858/* 857/*
859 This function inserts bits in the inflate input stream. The intent is 858 This function inserts bits in the inflate input stream. The intent is
860 that this function is used to start inflating at a bit position in the 859 that this function is used to start inflating at a bit position in the
861 middle of a byte. The provided bits will be used before any bytes are used 860 middle of a byte. The provided bits will be used before any bytes are used
862 from next_in. This function should only be used with raw inflate, and 861 from next_in. This function should only be used with raw inflate, and
863 should be used before the first inflate() call after inflateInit2() or 862 should be used before the first inflate() call after inflateInit2() or
864 inflateReset(). bits must be less than or equal to 16, and that many of the 863 inflateReset(). bits must be less than or equal to 16, and that many of the
865 least significant bits of value will be inserted in the input. 864 least significant bits of value will be inserted in the input.
866 865
867 If bits is negative, then the input stream bit buffer is emptied. Then 866 If bits is negative, then the input stream bit buffer is emptied. Then
868 inflatePrime() can be called again to put bits in the buffer. This is used 867 inflatePrime() can be called again to put bits in the buffer. This is used
869 to clear out bits leftover after feeding inflate a block description prior 868 to clear out bits leftover after feeding inflate a block description prior
870 to feeding inflate codes. 869 to feeding inflate codes.
871 870
872 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 871 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
873 stream state was inconsistent. 872 stream state was inconsistent.
874*/ 873*/
875 874
@@ -891,20 +890,20 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
891 decoding of the code, or if it has completed decoding but is waiting for 890 decoding of the code, or if it has completed decoding but is waiting for
892 more output space to write the literal or match data. 891 more output space to write the literal or match data.
893 892
894 inflateMark() is used to mark locations in the input data for random 893 inflateMark() is used to mark locations in the input data for random
895 access, which may be at bit positions, and to note those cases where the 894 access, which may be at bit positions, and to note those cases where the
896 output of a code may span boundaries of random access blocks. The current 895 output of a code may span boundaries of random access blocks. The current
897 location in the input stream can be determined from avail_in and data_type 896 location in the input stream can be determined from avail_in and data_type
898 as noted in the description for the Z_BLOCK flush parameter for inflate. 897 as noted in the description for the Z_BLOCK flush parameter for inflate.
899 898
900 inflateMark returns the value noted above or -1 << 16 if the provided 899 inflateMark returns the value noted above or -1 << 16 if the provided
901 source stream state was inconsistent. 900 source stream state was inconsistent.
902*/ 901*/
903 902
904ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 903ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
905 gz_headerp head)); 904 gz_headerp head));
906/* 905/*
907 inflateGetHeader() requests that gzip header information be stored in the 906 inflateGetHeader() requests that gzip header information be stored in the
908 provided gz_header structure. inflateGetHeader() may be called after 907 provided gz_header structure. inflateGetHeader() may be called after
909 inflateInit2() or inflateReset(), and before the first call of inflate(). 908 inflateInit2() or inflateReset(), and before the first call of inflate().
910 As inflate() processes the gzip stream, head->done is zero until the header 909 As inflate() processes the gzip stream, head->done is zero until the header
@@ -914,30 +913,30 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
914 used to force inflate() to return immediately after header processing is 913 used to force inflate() to return immediately after header processing is
915 complete and before any actual data is decompressed. 914 complete and before any actual data is decompressed.
916 915
917 The text, time, xflags, and os fields are filled in with the gzip header 916 The text, time, xflags, and os fields are filled in with the gzip header
918 contents. hcrc is set to true if there is a header CRC. (The header CRC 917 contents. hcrc is set to true if there is a header CRC. (The header CRC
919 was valid if done is set to one.) If extra is not Z_NULL, then extra_max 918 was valid if done is set to one.) If extra is not Z_NULL, then extra_max
920 contains the maximum number of bytes to write to extra. Once done is true, 919 contains the maximum number of bytes to write to extra. Once done is true,
921 extra_len contains the actual extra field length, and extra contains the 920 extra_len contains the actual extra field length, and extra contains the
922 extra field, or that field truncated if extra_max is less than extra_len. 921 extra field, or that field truncated if extra_max is less than extra_len.
923 If name is not Z_NULL, then up to name_max characters are written there, 922 If name is not Z_NULL, then up to name_max characters are written there,
924 terminated with a zero unless the length is greater than name_max. If 923 terminated with a zero unless the length is greater than name_max. If
925 comment is not Z_NULL, then up to comm_max characters are written there, 924 comment is not Z_NULL, then up to comm_max characters are written there,
926 terminated with a zero unless the length is greater than comm_max. When 925 terminated with a zero unless the length is greater than comm_max. When any
927 any of extra, name, or comment are not Z_NULL and the respective field is 926 of extra, name, or comment are not Z_NULL and the respective field is not
928 not present in the header, then that field is set to Z_NULL to signal its 927 present in the header, then that field is set to Z_NULL to signal its
929 absence. This allows the use of deflateSetHeader() with the returned 928 absence. This allows the use of deflateSetHeader() with the returned
930 structure to duplicate the header. However if those fields are set to 929 structure to duplicate the header. However if those fields are set to
931 allocated memory, then the application will need to save those pointers 930 allocated memory, then the application will need to save those pointers
932 elsewhere so that they can be eventually freed. 931 elsewhere so that they can be eventually freed.
933 932
934 If inflateGetHeader is not used, then the header information is simply 933 If inflateGetHeader is not used, then the header information is simply
935 discarded. The header is always checked for validity, including the header 934 discarded. The header is always checked for validity, including the header
936 CRC if present. inflateReset() will reset the process to discard the header 935 CRC if present. inflateReset() will reset the process to discard the header
937 information. The application would need to call inflateGetHeader() again to 936 information. The application would need to call inflateGetHeader() again to
938 retrieve the header from the next gzip stream. 937 retrieve the header from the next gzip stream.
939 938
940 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 939 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
941 stream state was inconsistent. 940 stream state was inconsistent.
942*/ 941*/
943 942
@@ -958,9 +957,9 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
958 See inflateBack() for the usage of these routines. 957 See inflateBack() for the usage of these routines.
959 958
960 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 959 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
961 the paramaters are invalid, Z_MEM_ERROR if the internal state could not 960 the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
962 be allocated, or Z_VERSION_ERROR if the version of the library does not 961 allocated, or Z_VERSION_ERROR if the version of the library does not match
963 match the version of the header file. 962 the version of the header file.
964*/ 963*/
965 964
966typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 965typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
@@ -980,15 +979,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
980 inflateBackInit() must be called first to allocate the internal state 979 inflateBackInit() must be called first to allocate the internal state
981 and to initialize the state with the user-provided window buffer. 980 and to initialize the state with the user-provided window buffer.
982 inflateBack() may then be used multiple times to inflate a complete, raw 981 inflateBack() may then be used multiple times to inflate a complete, raw
983 deflate stream with each call. inflateBackEnd() is then called to free 982 deflate stream with each call. inflateBackEnd() is then called to free the
984 the allocated state. 983 allocated state.
985 984
986 A raw deflate stream is one with no zlib or gzip header or trailer. 985 A raw deflate stream is one with no zlib or gzip header or trailer.
987 This routine would normally be used in a utility that reads zip or gzip 986 This routine would normally be used in a utility that reads zip or gzip
988 files and writes out uncompressed files. The utility would decode the 987 files and writes out uncompressed files. The utility would decode the
989 header and process the trailer on its own, hence this routine expects 988 header and process the trailer on its own, hence this routine expects only
990 only the raw deflate stream to decompress. This is different from the 989 the raw deflate stream to decompress. This is different from the normal
991 normal behavior of inflate(), which expects either a zlib or gzip header and 990 behavior of inflate(), which expects either a zlib or gzip header and
992 trailer around the deflate stream. 991 trailer around the deflate stream.
993 992
994 inflateBack() uses two subroutines supplied by the caller that are then 993 inflateBack() uses two subroutines supplied by the caller that are then
@@ -1014,7 +1013,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1014 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 1013 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
1015 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 1014 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
1016 must also be initialized, and then if strm->avail_in is not zero, input will 1015 must also be initialized, and then if strm->avail_in is not zero, input will
1017 initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 1016 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1018 1017
1019 The in_desc and out_desc parameters of inflateBack() is passed as the 1018 The in_desc and out_desc parameters of inflateBack() is passed as the
1020 first parameter of in() and out() respectively when they are called. These 1019 first parameter of in() and out() respectively when they are called. These
@@ -1024,15 +1023,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1024 On return, inflateBack() will set strm->next_in and strm->avail_in to 1023 On return, inflateBack() will set strm->next_in and strm->avail_in to
1025 pass back any unused input that was provided by the last in() call. The 1024 pass back any unused input that was provided by the last in() call. The
1026 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 1025 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
1027 if in() or out() returned an error, Z_DATA_ERROR if there was a format 1026 if in() or out() returned an error, Z_DATA_ERROR if there was a format error
1028 error in the deflate stream (in which case strm->msg is set to indicate the 1027 in the deflate stream (in which case strm->msg is set to indicate the nature
1029 nature of the error), or Z_STREAM_ERROR if the stream was not properly 1028 of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
1030 initialized. In the case of Z_BUF_ERROR, an input or output error can be 1029 In the case of Z_BUF_ERROR, an input or output error can be distinguished
1031 distinguished using strm->next_in which will be Z_NULL only if in() returned 1030 using strm->next_in which will be Z_NULL only if in() returned an error. If
1032 an error. If strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to 1031 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1033 out() returning non-zero. (in() will always be called before out(), so 1032 non-zero. (in() will always be called before out(), so strm->next_in is
1034 strm->next_in is assured to be defined if out() returns non-zero.) Note 1033 assured to be defined if out() returns non-zero.) Note that inflateBack()
1035 that inflateBack() cannot return Z_OK. 1034 cannot return Z_OK.
1036*/ 1035*/
1037 1036
1038ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 1037ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
@@ -1089,22 +1088,21 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1089 1088
1090/* 1089/*
1091 The following utility functions are implemented on top of the 1090 The following utility functions are implemented on top of the
1092 basic stream-oriented functions. To simplify the interface, some 1091 basic stream-oriented functions. To simplify the interface, some default
1093 default options are assumed (compression level and memory usage, 1092 options are assumed (compression level and memory usage, standard memory
1094 standard memory allocation functions). The source code of these 1093 allocation functions). The source code of these utility functions can
1095 utility functions can easily be modified if you need special options. 1094 easily be modified if you need special options.
1096*/ 1095*/
1097 1096
1098ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 1097ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1099 const Bytef *source, uLong sourceLen)); 1098 const Bytef *source, uLong sourceLen));
1100/* 1099/*
1101 Compresses the source buffer into the destination buffer. sourceLen is 1100 Compresses the source buffer into the destination buffer. sourceLen is
1102 the byte length of the source buffer. Upon entry, destLen is the total 1101 the byte length of the source buffer. Upon entry, destLen is the total size
1103 size of the destination buffer, which must be at least the value returned 1102 of the destination buffer, which must be at least the value returned by
1104 by compressBound(sourceLen). Upon exit, destLen is the actual size of the 1103 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1105 compressed buffer. 1104 compressed buffer.
1106 This function can be used to compress a whole file at once if the 1105
1107 input file is mmap'ed.
1108 compress returns Z_OK if success, Z_MEM_ERROR if there was not 1106 compress returns Z_OK if success, Z_MEM_ERROR if there was not
1109 enough memory, Z_BUF_ERROR if there was not enough room in the output 1107 enough memory, Z_BUF_ERROR if there was not enough room in the output
1110 buffer. 1108 buffer.
@@ -1114,11 +1112,11 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1114 const Bytef *source, uLong sourceLen, 1112 const Bytef *source, uLong sourceLen,
1115 int level)); 1113 int level));
1116/* 1114/*
1117 Compresses the source buffer into the destination buffer. The level 1115 Compresses the source buffer into the destination buffer. The level
1118 parameter has the same meaning as in deflateInit. sourceLen is the byte 1116 parameter has the same meaning as in deflateInit. sourceLen is the byte
1119 length of the source buffer. Upon entry, destLen is the total size of the 1117 length of the source buffer. Upon entry, destLen is the total size of the
1120 destination buffer, which must be at least the value returned by 1118 destination buffer, which must be at least the value returned by
1121 compressBound(sourceLen). Upon exit, destLen is the actual size of the 1119 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1122 compressed buffer. 1120 compressed buffer.
1123 1121
1124 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 1122 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
@@ -1129,22 +1127,20 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1129ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 1127ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1130/* 1128/*
1131 compressBound() returns an upper bound on the compressed size after 1129 compressBound() returns an upper bound on the compressed size after
1132 compress() or compress2() on sourceLen bytes. It would be used before 1130 compress() or compress2() on sourceLen bytes. It would be used before a
1133 a compress() or compress2() call to allocate the destination buffer. 1131 compress() or compress2() call to allocate the destination buffer.
1134*/ 1132*/
1135 1133
1136ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 1134ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1137 const Bytef *source, uLong sourceLen)); 1135 const Bytef *source, uLong sourceLen));
1138/* 1136/*
1139 Decompresses the source buffer into the destination buffer. sourceLen is 1137 Decompresses the source buffer into the destination buffer. sourceLen is
1140 the byte length of the source buffer. Upon entry, destLen is the total 1138 the byte length of the source buffer. Upon entry, destLen is the total size
1141 size of the destination buffer, which must be large enough to hold the 1139 of the destination buffer, which must be large enough to hold the entire
1142 entire uncompressed data. (The size of the uncompressed data must have 1140 uncompressed data. (The size of the uncompressed data must have been saved
1143 been saved previously by the compressor and transmitted to the decompressor 1141 previously by the compressor and transmitted to the decompressor by some
1144 by some mechanism outside the scope of this compression library.) 1142 mechanism outside the scope of this compression library.) Upon exit, destLen
1145 Upon exit, destLen is the actual size of the uncompressed buffer. 1143 is the actual size of the uncompressed buffer.
1146 This function can be used to decompress a whole file at once if the
1147 input file is mmap'ed.
1148 1144
1149 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1145 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1150 enough memory, Z_BUF_ERROR if there was not enough room in the output 1146 enough memory, Z_BUF_ERROR if there was not enough room in the output
@@ -1153,10 +1149,9 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1153 1149
1154/* 1150/*
1155 This library supports reading and writing files in gzip (.gz) format 1151 This library supports reading and writing files in gzip (.gz) format
1156 with an interface similar to that of stdio using the functions that start 1152 with an interface similar to that of stdio using the functions that start
1157 with "gz". The gzip format is different from the zlib format. gzip is a 1153 with "gz". The gzip format is different from the zlib format. gzip is a
1158 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 1154 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
1159
1160*/ 1155*/
1161 1156
1162typedef voidp gzFile; 1157typedef voidp gzFile;
@@ -1164,148 +1159,174 @@ typedef voidp gzFile;
1164/* 1159/*
1165ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 1160ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1166 1161
1167 Opens a gzip (.gz) file for reading or writing. The mode parameter 1162 Opens a gzip (.gz) file for reading or writing. The mode parameter is as
1168 is as in fopen ("rb" or "wb") but can also include a compression level 1163 in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
1169 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 1164 a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
1170 Huffman only compression as in "wb1h", or 'R' for run-length encoding 1165 compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
1171 as in "wb1R". (See the description of deflateInit2 for more information 1166 for fixed code compression as in "wb9F". (See the description of
1172 about the strategy parameter.) 1167 deflateInit2 for more information about the strategy parameter.) Also "a"
1168 can be used instead of "w" to request that the gzip stream that will be
1169 written be appended to the file. "+" will result in an error, since reading
1170 and writing to the same gzip file is not supported.
1173 1171
1174 gzopen can be used to read a file which is not in gzip format; in this 1172 gzopen can be used to read a file which is not in gzip format; in this
1175 case gzread will directly read from the file without decompression. 1173 case gzread will directly read from the file without decompression.
1176 1174
1177 gzopen returns NULL if the file could not be opened or if there was 1175 gzopen returns NULL if the file could not be opened or if there was
1178 insufficient memory to allocate the (de)compression state; errno 1176 insufficient memory to allocate the (de)compression state; errno can be
1179 can be checked to distinguish the two cases (if errno is zero, the 1177 checked to distinguish the two cases (if errno is zero, the zlib error is
1180 zlib error is Z_MEM_ERROR). */ 1178 Z_MEM_ERROR).
1179*/
1181 1180
1182ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 1181ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1183/* 1182/*
1184 gzdopen() associates a gzFile with the file descriptor fd. File 1183 gzdopen() associates a gzFile with the file descriptor fd. File
1185 descriptors are obtained from calls like open, dup, creat, pipe or 1184 descriptors are obtained from calls like open, dup, creat, pipe or fileno
1186 fileno (in the file has been previously opened with fopen). 1185 (in the file has been previously opened with fopen). The mode parameter is
1187 The mode parameter is as in gzopen. 1186 as in gzopen.
1188 The next call of gzclose on the returned gzFile will also close the 1187
1189 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 1188 The next call of gzclose on the returned gzFile will also close the file
1190 descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 1189 descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor
1191 gzdopen returns NULL if there was insufficient memory to allocate 1190 fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
1192 the (de)compression state. 1191
1192 gzdopen returns NULL if there was insufficient memory to allocate the
1193 (de)compression state.
1193*/ 1194*/
1194 1195
1195ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); 1196ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1196/* 1197/*
1197 Set the internal buffer size used by this library's functions. The default 1198 Set the internal buffer size used by this library's functions. The
1198 buffer size is 8192 bytes. This function must be called after gz_open() or 1199 default buffer size is 8192 bytes. This function must be called after
1199 gz_dopen(), and before any other calls that read or write the file. The 1200 gzopen() or gzdopen(), and before any other calls that read or write the
1200 buffer memory allocation is always deferred to the first read or write. Two 1201 file. The buffer memory allocation is always deferred to the first read or
1201 buffers are allocated, either both of the specified size when writing, or 1202 write. Two buffers are allocated, either both of the specified size when
1202 one of the specified size and the other twice that size when reading. A 1203 writing, or one of the specified size and the other twice that size when
1203 larger buffer size of, for example, 64K or 128K bytes will noticeably 1204 reading. A larger buffer size of, for example, 64K or 128K bytes will
1204 increase the speed of decompression (reading). 1205 noticeably increase the speed of decompression (reading).
1205 gz_buffer() returns 0 on success, or -1 on failure, such as being called 1206
1207 The new buffer size also affects the maximum length for gzprintf().
1208
1209 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1206 too late. 1210 too late.
1207*/ 1211*/
1208 1212
1209ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 1213ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1210/* 1214/*
1211 Dynamically update the compression level or strategy. See the description 1215 Dynamically update the compression level or strategy. See the description
1212 of deflateInit2 for the meaning of these parameters. 1216 of deflateInit2 for the meaning of these parameters.
1217
1213 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 1218 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1214 opened for writing. 1219 opened for writing.
1215*/ 1220*/
1216 1221
1217ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 1222ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1218/* 1223/*
1219 Reads the given number of uncompressed bytes from the compressed file. 1224 Reads the given number of uncompressed bytes from the compressed file. If
1220 If the input file was not in gzip format, gzread copies the given number 1225 the input file was not in gzip format, gzread copies the given number of
1221 of bytes into the buffer. 1226 bytes into the buffer.
1222 gzread returns the number of uncompressed bytes actually read (0 for 1227
1223 end of file, -1 for error). */ 1228 After reaching the end of a gzip stream in the input, gzread will continue
1229 to read, looking for another gzip stream, or failing that, reading the rest
1230 of the input file directly without decompression. The entire input file
1231 will be read if gzread is called until it returns less than the requested
1232 len.
1233
1234 gzread returns the number of uncompressed bytes actually read (less than
1235 len for end of file, -1 for error).
1236*/
1224 1237
1225ZEXTERN int ZEXPORT gzwrite OF((gzFile file, 1238ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1226 voidpc buf, unsigned len)); 1239 voidpc buf, unsigned len));
1227/* 1240/*
1228 Writes the given number of uncompressed bytes into the compressed file. 1241 Writes the given number of uncompressed bytes into the compressed file.
1229 gzwrite returns the number of uncompressed bytes actually written 1242 gzwrite returns the number of uncompressed bytes actually written (0 in case
1230 (0 in case of error). 1243 of error).
1231*/ 1244*/
1232 1245
1233ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 1246ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
1234/* 1247/*
1235 Converts, formats, and writes the arguments to the compressed file under 1248 Converts, formats, and writes the arguments to the compressed file under
1236 control of the format string, as in fprintf. gzprintf returns the number of 1249 control of the format string, as in fprintf. gzprintf returns the number of
1237 uncompressed bytes actually written, or 0 in case of error. The number of 1250 uncompressed bytes actually written, or 0 in case of error. The number of
1238 uncompressed bytes written is limited to 8191, or one less than the buffer 1251 uncompressed bytes written is limited to 8191, or one less than the buffer
1239 size given to gz_buffer(). The caller should assure that this limit is not 1252 size given to gzbuffer(). The caller should assure that this limit is not
1240 exceeded. If it is exceeded, then gzprintf() will return an error (0) with 1253 exceeded. If it is exceeded, then gzprintf() will return an error (0) with
1241 nothing written. In this case, there may also be a buffer overflow with 1254 nothing written. In this case, there may also be a buffer overflow with
1242 unpredictable consequences, which is possible only if zlib was compiled 1255 unpredictable consequences, which is possible only if zlib was compiled with
1243 with the insecure functions sprintf() or vsprintf() because the secure 1256 the insecure functions sprintf() or vsprintf() because the secure snprintf()
1244 snprintf() or vsnprintf() functions were not available. 1257 or vsnprintf() functions were not available. This can be checked for using
1258 zlibCompileFlags().
1245*/ 1259*/
1246 1260
1247ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 1261ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1248/* 1262/*
1249 Writes the given null-terminated string to the compressed file, excluding 1263 Writes the given null-terminated string to the compressed file, excluding
1250 the terminating null character. 1264 the terminating null character.
1251 gzputs returns the number of characters written, or -1 in case of error. 1265
1266 gzputs returns the number of characters written, or -1 in case of error.
1252*/ 1267*/
1253 1268
1254ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 1269ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1255/* 1270/*
1256 Reads bytes from the compressed file until len-1 characters are read, or 1271 Reads bytes from the compressed file until len-1 characters are read, or
1257 a newline character is read and transferred to buf, or an end-of-file 1272 a newline character is read and transferred to buf, or an end-of-file
1258 condition is encountered. The string is then terminated with a null 1273 condition is encountered. The string is then terminated with a null
1259 character. 1274 character.
1260 gzgets returns buf, or Z_NULL in case of error. 1275
1276 gzgets returns buf, or Z_NULL in case of error.
1261*/ 1277*/
1262 1278
1263ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 1279ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1264/* 1280/*
1265 Writes c, converted to an unsigned char, into the compressed file. 1281 Writes c, converted to an unsigned char, into the compressed file. gzputc
1266 gzputc returns the value that was written, or -1 in case of error. 1282 returns the value that was written, or -1 in case of error.
1267*/ 1283*/
1268 1284
1269ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 1285ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1270/* 1286/*
1271 Reads one byte from the compressed file. gzgetc returns this byte 1287 Reads one byte from the compressed file. gzgetc returns this byte or -1
1272 or -1 in case of end of file or error. 1288 in case of end of file or error.
1273*/ 1289*/
1274 1290
1275ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 1291ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1276/* 1292/*
1277 Push one character back onto the stream to be read again later. 1293 Push one character back onto the stream to be read again later. At least
1278 Only one character of push-back is allowed. gzungetc() returns the 1294 one character of push-back is allowed. gzungetc() returns the character
1279 character pushed, or -1 on failure. gzungetc() will fail if a 1295 pushed, or -1 on failure. gzungetc() will fail if c is -1, and may fail if
1280 character has been pushed but not read yet, or if c is -1. The pushed 1296 a character has been pushed but not read yet. The pushed character will be
1281 character will be discarded if the stream is repositioned with gzseek() 1297 discarded if the stream is repositioned with gzseek() or gzrewind().
1282 or gzrewind().
1283*/ 1298*/
1284 1299
1285ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 1300ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1286/* 1301/*
1287 Flushes all pending output into the compressed file. The parameter 1302 Flushes all pending output into the compressed file. The parameter flush
1288 flush is as in the deflate() function. The return value is the zlib 1303 is as in the deflate() function. The return value is the zlib error number
1289 error number (see function gzerror below). gzflush returns Z_OK if 1304 (see function gzerror below).
1290 the flush parameter is Z_FINISH and all output could be flushed. 1305
1291 gzflush should be called only when strictly necessary because it can 1306 If the flush parameter is Z_FINISH, the remaining data is written and the
1292 degrade compression. 1307 gzip stream is completed in the output. If gzwrite() is called again, a new
1308 gzip stream will be started in the output. gzread() is able to read such
1309 concatented gzip streams.
1310
1311 gzflush should be called only when strictly necessary because it will
1312 degrade compression if called too often.
1293*/ 1313*/
1294 1314
1295/* 1315/*
1296ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 1316ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1297 z_off_t offset, int whence)); 1317 z_off_t offset, int whence));
1298 1318
1299 Sets the starting position for the next gzread or gzwrite on the 1319 Sets the starting position for the next gzread or gzwrite on the given
1300 given compressed file. The offset represents a number of bytes in the 1320 compressed file. The offset represents a number of bytes in the
1301 uncompressed data stream. The whence parameter is defined as in lseek(2); 1321 uncompressed data stream. The whence parameter is defined as in lseek(2);
1302 the value SEEK_END is not supported. 1322 the value SEEK_END is not supported.
1323
1303 If the file is opened for reading, this function is emulated but can be 1324 If the file is opened for reading, this function is emulated but can be
1304 extremely slow. If the file is opened for writing, only forward seeks are 1325 extremely slow. If the file is opened for writing, only forward seeks are
1305 supported; gzseek then compresses a sequence of zeroes up to the new 1326 supported; gzseek then compresses a sequence of zeroes up to the new
1306 starting position. 1327 starting position.
1307 1328
1308 gzseek returns the resulting offset location as measured in bytes from 1329 gzseek returns the resulting offset location as measured in bytes from
1309 the beginning of the uncompressed stream, or -1 in case of error, in 1330 the beginning of the uncompressed stream, or -1 in case of error, in
1310 particular if the file is opened for writing and the new starting position 1331 particular if the file is opened for writing and the new starting position
1311 would be before the current position. 1332 would be before the current position.
@@ -1315,47 +1336,50 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1315/* 1336/*
1316 Rewinds the given file. This function is supported only for reading. 1337 Rewinds the given file. This function is supported only for reading.
1317 1338
1318 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 1339 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1319*/ 1340*/
1320 1341
1321/* 1342/*
1322ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 1343ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1323 1344
1324 Returns the starting position for the next gzread or gzwrite on the 1345 Returns the starting position for the next gzread or gzwrite on the given
1325 given compressed file. This position represents a number of bytes in the 1346 compressed file. This position represents a number of bytes in the
1326 uncompressed data stream, and is zero when starting, even if appending 1347 uncompressed data stream, and is zero when starting, even if appending or
1327 or reading a gzip stream from the middle of a file using gz_dopen(). 1348 reading a gzip stream from the middle of a file using gzdopen().
1328 1349
1329 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 1350 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1330*/ 1351*/
1331 1352
1332/* 1353/*
1333ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); 1354ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1334 1355
1335 Returns the current offset in the file being read or written. This offset 1356 Returns the current offset in the file being read or written. This offset
1336 includes the count of bytes that precede the gzip stream, for example when 1357 includes the count of bytes that precede the gzip stream, for example when
1337 appending or when using gz_dopen() for reading. When reading, the offset 1358 appending or when using gzdopen() for reading. When reading, the offset
1338 includes data that has been used to generate what has been provided as 1359 includes data that has been used to generate what has been provided as
1339 uncompressed data so far, but does not include as yet unused buffered input. 1360 uncompressed data so far, but does not include as yet unused buffered input.
1340 On error, gz_offset() returns -1. 1361 On error, gzoffset() returns -1.
1341*/ 1362*/
1342 1363
1343ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 1364ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1344/* 1365/*
1345 Returns 1 when EOF has previously been detected reading the given 1366 Returns 1 when EOF has previously been detected reading the given input
1346 input stream, otherwise zero. 1367 stream, otherwise zero.
1347*/ 1368*/
1348 1369
1349ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 1370ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1350/* 1371/*
1351 Returns 1 if file is being read directly without decompression, otherwise 1372 Returns 1 if file is being read directly without decompression, otherwise
1352 zero. 1373 zero. gzdirect() called immediately after gzopen() will always return zero,
1374 since nothing has been read yet. Whether to read the file with
1375 decompression or not is not determined until after the first read operation
1376 (e.g. gzread(), gzgetc(), etc.).
1353*/ 1377*/
1354 1378
1355ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 1379ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1356/* 1380/*
1357 Flushes all pending output if necessary, closes the compressed file 1381 Flushes all pending output if necessary, closes the compressed file and
1358 and deallocates all the (de)compression state. The return value is the zlib 1382 deallocates all the (de)compression state. The return value is the zlib
1359 error number. Note that once file is closed, you cannot call gzerror with 1383 error number. Note that once file is closed, you cannot call gzerror with
1360 file, since its structures have been deallocated. 1384 file, since its structures have been deallocated.
1361*/ 1385*/
@@ -1363,31 +1387,31 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1363ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); 1387ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1364ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); 1388ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1365/* 1389/*
1366 Same as gz_close(), but gz_close_r() is only for use when reading, and 1390 Same as gzclose(), but gzclose_r() is only for use when reading, and
1367 gz_close_w() is only for use when writing. The advantage to using these 1391 gzclose_w() is only for use when writing. The advantage to using these
1368 instead of gz_close() is that they avoid linking in zlib compression or 1392 instead of gzclose() is that they avoid linking in zlib compression or
1369 decompression code that is not used when only reading or only writing 1393 decompression code that is not used when only reading or only writing
1370 respectively. If gz_close() is used, then both compression and 1394 respectively. If gzclose() is used, then both compression and decompression
1371 decompression code will be included the application when linking to a 1395 code will be included the application when linking to a static zlib library.
1372 static zlib library.
1373*/ 1396*/
1374 1397
1375ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 1398ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1376/* 1399/*
1377 Returns the error message for the last error which occurred on the 1400 Returns the error message for the last error which occurred on the given
1378 given compressed file. errnum is set to zlib error number. If an 1401 compressed file. errnum is set to zlib error number. If an error occurred
1379 error occurred in the file system and not in the compression library, 1402 in the file system and not in the compression library, errnum is set to
1380 errnum is set to Z_ERRNO and the application may consult errno 1403 Z_ERRNO and the application may consult errno to get the exact error code.
1381 to get the exact error code.
1382 1404
1383 The application must not modify the returned string and future calls to 1405 The application must not modify the returned string. Future calls to
1384 this function may invalidate the returned string. 1406 this function may invalidate the previously returned string. If file is
1407 closed, then the string previously returned by gzerror will no longer be
1408 available.
1385*/ 1409*/
1386 1410
1387ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 1411ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1388/* 1412/*
1389 Clears the error and end-of-file flags for file. This is analogous to the 1413 Clears the error and end-of-file flags for file. This is analogous to the
1390 clearerr() function in stdio. This is useful for continuing to read a gzip 1414 clearerr() function in stdio. This is useful for continuing to read a gzip
1391 file that is being written concurrently. 1415 file that is being written concurrently.
1392*/ 1416*/
1393 1417
@@ -1395,17 +1419,20 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1395 1419
1396/* 1420/*
1397 These functions are not related to compression but are exported 1421 These functions are not related to compression but are exported
1398 anyway because they might be useful in applications using the 1422 anyway because they might be useful in applications using the compression
1399 compression library. 1423 library.
1400*/ 1424*/
1401 1425
1402ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 1426ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1403/* 1427/*
1404 Update a running Adler-32 checksum with the bytes buf[0..len-1] and 1428 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1405 return the updated checksum. If buf is Z_NULL, this function returns 1429 return the updated checksum. If buf is Z_NULL, this function returns the
1406 the required initial value for the checksum. 1430 required initial value for the checksum.
1407 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 1431
1408 much faster. Usage example: 1432 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1433 much faster.
1434
1435 Usage example:
1409 1436
1410 uLong adler = adler32(0L, Z_NULL, 0); 1437 uLong adler = adler32(0L, Z_NULL, 0);
1411 1438
@@ -1428,9 +1455,11 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1428ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 1455ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1429/* 1456/*
1430 Update a running CRC-32 with the bytes buf[0..len-1] and return the 1457 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1431 updated CRC-32. If buf is Z_NULL, this function returns the required initial 1458 updated CRC-32. If buf is Z_NULL, this function returns the required
1432 value for the for the crc. Pre- and post-conditioning (one's complement) is 1459 initial value for the for the crc. Pre- and post-conditioning (one's
1433 performed within this function so it shouldn't be done by the application. 1460 complement) is performed within this function so it shouldn't be done by the
1461 application.
1462
1434 Usage example: 1463 Usage example:
1435 1464
1436 uLong crc = crc32(0L, Z_NULL, 0); 1465 uLong crc = crc32(0L, Z_NULL, 0);