summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2016-11-14 10:19:25 -0700
committerMark Adler <madler@alumni.caltech.edu>2016-12-04 07:48:41 -0800
commit001300d0d91f75f03eed5ec97eca160452f62d61 (patch)
treedf45fa0c8de461d27ffb9c68a1b9c7a2a72d0b8f
parent9674807c82ae06716a678d7374362acdb6f041b5 (diff)
downloadzlib-001300d0d91f75f03eed5ec97eca160452f62d61.tar.gz
zlib-001300d0d91f75f03eed5ec97eca160452f62d61.tar.bz2
zlib-001300d0d91f75f03eed5ec97eca160452f62d61.zip
Minor edits to the documentation in source file contents.
-rw-r--r--zconf.h2
-rw-r--r--zconf.h.cmakein2
-rw-r--r--zconf.h.in2
-rw-r--r--zlib.h196
4 files changed, 109 insertions, 93 deletions
diff --git a/zconf.h b/zconf.h
index 0a4828e..d09f186 100644
--- a/zconf.h
+++ b/zconf.h
@@ -251,7 +251,7 @@
251 Of course this will generally degrade compression (there's no free lunch). 251 Of course this will generally degrade compression (there's no free lunch).
252 252
253 The memory requirements for inflate are (in bytes) 1 << windowBits 253 The memory requirements for inflate are (in bytes) 1 << windowBits
254 that is, 32K for windowBits=15 (default value) plus a few kilobytes 254 that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
255 for small objects. 255 for small objects.
256*/ 256*/
257 257
diff --git a/zconf.h.cmakein b/zconf.h.cmakein
index 752eb88..70942e4 100644
--- a/zconf.h.cmakein
+++ b/zconf.h.cmakein
@@ -253,7 +253,7 @@
253 Of course this will generally degrade compression (there's no free lunch). 253 Of course this will generally degrade compression (there's no free lunch).
254 254
255 The memory requirements for inflate are (in bytes) 1 << windowBits 255 The memory requirements for inflate are (in bytes) 1 << windowBits
256 that is, 32K for windowBits=15 (default value) plus a few kilobytes 256 that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
257 for small objects. 257 for small objects.
258*/ 258*/
259 259
diff --git a/zconf.h.in b/zconf.h.in
index 0a4828e..d09f186 100644
--- a/zconf.h.in
+++ b/zconf.h.in
@@ -251,7 +251,7 @@
251 Of course this will generally degrade compression (there's no free lunch). 251 Of course this will generally degrade compression (there's no free lunch).
252 252
253 The memory requirements for inflate are (in bytes) 1 << windowBits 253 The memory requirements for inflate are (in bytes) 1 << windowBits
254 that is, 32K for windowBits=15 (default value) plus a few kilobytes 254 that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
255 for small objects. 255 for small objects.
256*/ 256*/
257 257
diff --git a/zlib.h b/zlib.h
index fc969af..5c99039 100644
--- a/zlib.h
+++ b/zlib.h
@@ -65,7 +65,8 @@ extern "C" {
65 with "gz". The gzip format is different from the zlib format. gzip is a 65 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. 66 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
67 67
68 This library can optionally read and write gzip streams in memory as well. 68 This library can optionally read and write gzip and raw deflate streams in
69 memory as well.
69 70
70 The zlib format was designed to be compact and fast for use in memory 71 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- 72 and on communications channels. The gzip format was designed for single-
@@ -74,7 +75,7 @@ extern "C" {
74 75
75 The library does not install any signal handler. The decoder checks 76 The library does not install any signal handler. The decoder checks
76 the consistency of the compressed data, so the library should never crash 77 the consistency of the compressed data, so the library should never crash
77 even in case of corrupted input. 78 even in the case of corrupted input.
78*/ 79*/
79 80
80typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 81typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
@@ -87,7 +88,7 @@ typedef struct z_stream_s {
87 uInt avail_in; /* number of bytes available at next_in */ 88 uInt avail_in; /* number of bytes available at next_in */
88 uLong total_in; /* total number of input bytes read so far */ 89 uLong total_in; /* total number of input bytes read so far */
89 90
90 Bytef *next_out; /* next output byte should be put there */ 91 Bytef *next_out; /* next output byte will go here */
91 uInt avail_out; /* remaining free space at next_out */ 92 uInt avail_out; /* remaining free space at next_out */
92 uLong total_out; /* total number of bytes output so far */ 93 uLong total_out; /* total number of bytes output so far */
93 94
@@ -98,8 +99,9 @@ typedef struct z_stream_s {
98 free_func zfree; /* used to free the internal state */ 99 free_func zfree; /* used to free the internal state */
99 voidpf opaque; /* private data object passed to zalloc and zfree */ 100 voidpf opaque; /* private data object passed to zalloc and zfree */
100 101
101 int data_type; /* best guess about the data type: binary or text */ 102 int data_type; /* best guess about the data type: binary or text
102 uLong adler; /* adler32 value of the uncompressed data */ 103 for deflate, or the decoding state for inflate */
104 uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */
103 uLong reserved; /* reserved for future use */ 105 uLong reserved; /* reserved for future use */
104} z_stream; 106} z_stream;
105 107
@@ -142,7 +144,9 @@ typedef gz_header FAR *gz_headerp;
142 144
143 zalloc must return Z_NULL if there is not enough memory for the object. 145 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 146 If zlib is used in a multi-threaded application, zalloc and zfree must be
145 thread safe. 147 thread safe. In that case, zlib is thread-safe. When zalloc and zfree are
148 Z_NULL on entry to the initialization function, they are set to internal
149 routines that use the standard library functions malloc() and free().
146 150
147 On 16-bit systems, the functions zalloc and zfree must be able to allocate 151 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 if 152 exactly 65536 bytes, but will not be required to allocate more than this if
@@ -155,7 +159,7 @@ typedef gz_header FAR *gz_headerp;
155 159
156 The fields total_in and total_out can be used for statistics or progress 160 The fields total_in and total_out can be used for statistics or progress
157 reports. After compression, total_in holds the total size of the 161 reports. After compression, total_in holds the total size of the
158 uncompressed data and may be saved for use in the decompressor (particularly 162 uncompressed data and may be saved for use by the decompressor (particularly
159 if the decompressor wants to decompress everything in a single step). 163 if the decompressor wants to decompress everything in a single step).
160*/ 164*/
161 165
@@ -200,7 +204,7 @@ typedef gz_header FAR *gz_headerp;
200#define Z_TEXT 1 204#define Z_TEXT 1
201#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 205#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
202#define Z_UNKNOWN 2 206#define Z_UNKNOWN 2
203/* Possible values of the data_type field (though see inflate()) */ 207/* Possible values of the data_type field for deflate() */
204 208
205#define Z_DEFLATED 8 209#define Z_DEFLATED 8
206/* The deflate compression method (the only one supported in this version) */ 210/* The deflate compression method (the only one supported in this version) */
@@ -258,11 +262,11 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
258 enough room in the output buffer), next_in and avail_in are updated and 262 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(). 263 processing will resume at this point for the next call of deflate().
260 264
261 - Provide more output starting at next_out and update next_out and avail_out 265 - Generate 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. 266 accordingly. This action is forced if the parameter flush is non zero.
263 Forcing flush frequently degrades the compression ratio, so this parameter 267 Forcing flush frequently degrades the compression ratio, so this parameter
264 should be set only when necessary (in interactive applications). Some 268 should be set only when necessary. Some output may be provided even if
265 output may be provided even if flush is not set. 269 flush is zero.
266 270
267 Before the call of deflate(), the application should ensure that at least 271 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 more 272 one of the actions is possible, by providing more input and/or consuming more
@@ -271,7 +275,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
271 output when it wants, for example when the output buffer is full (avail_out 275 output when it wants, for example when the output buffer is full (avail_out
272 == 0), or after each call of deflate(). If deflate returns Z_OK and with 276 == 0), or after each call of deflate(). If deflate returns Z_OK and with
273 zero avail_out, it must be called again after making room in the output 277 zero avail_out, it must be called again after making room in the output
274 buffer because there might be more output pending. 278 buffer because there might be more output pending. See deflatePending(),
279 which can be used if desired to determine whether or not there is more ouput
280 in that case.
275 281
276 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 282 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 283 decide how much data to accumulate before producing output, in order to
@@ -292,8 +298,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
292 input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. 298 input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
293 This completes the current deflate block and follows it with an empty fixed 299 This completes the current deflate block and follows it with an empty fixed
294 codes block that is 10 bits long. This assures that enough bytes are output 300 codes block that is 10 bits long. This assures that enough bytes are output
295 in order for the decompressor to finish the block before the empty fixed code 301 in order for the decompressor to finish the block before the empty fixed
296 block. 302 codes block.
297 303
298 If flush is set to Z_BLOCK, a deflate block is completed and emitted, as 304 If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
299 for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to 305 for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
@@ -319,34 +325,38 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
319 325
320 If the parameter flush is set to Z_FINISH, pending input is processed, 326 If the parameter flush is set to Z_FINISH, pending input is processed,
321 pending output is flushed and deflate returns with Z_STREAM_END if there was 327 pending output is flushed and deflate returns with Z_STREAM_END if there was
322 enough output space; if deflate returns with Z_OK, this function must be 328 enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this
323 called again with Z_FINISH and more output space (updated avail_out) but no 329 function must be called again with Z_FINISH and more output space (updated
324 more input data, until it returns with Z_STREAM_END or an error. After 330 avail_out) but no more input data, until it returns with Z_STREAM_END or an
325 deflate has returned Z_STREAM_END, the only possible operations on the stream 331 error. After deflate has returned Z_STREAM_END, the only possible operations
326 are deflateReset or deflateEnd. 332 on the stream are deflateReset or deflateEnd.
327 333
328 Z_FINISH can be used immediately after deflateInit if all the compression 334 Z_FINISH can be used in the first deflate call after deflateInit if all the
329 is to be done in a single step. In this case, avail_out must be at least the 335 compression is to be done in a single step. In order to complete in one
330 value returned by deflateBound (see below). Then deflate is guaranteed to 336 call, avail_out must be at least the value returned by deflateBound (see
331 return Z_STREAM_END. If not enough output space is provided, deflate will 337 below). Then deflate is guaranteed to return Z_STREAM_END. If not enough
332 not return Z_STREAM_END, and it must be called again as described above. 338 output space is provided, deflate will not return Z_STREAM_END, and it must
333 339 be called again as described above.
334 deflate() sets strm->adler to the adler32 checksum of all input read 340
335 so far (that is, total_in bytes). 341 deflate() sets strm->adler to the Adler-32 checksum of all input read
342 so far (that is, total_in bytes). If a gzip stream is being generated, then
343 strm->adler will be the CRC-32 checksum of the input read so far. (See
344 deflateInit2 below.)
336 345
337 deflate() may update strm->data_type if it can make a good guess about 346 deflate() may update strm->data_type if it can make a good guess about
338 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 347 the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is
339 binary. This field is only for information purposes and does not affect the 348 considered binary. This field is only for information purposes and does not
340 compression algorithm in any manner. 349 affect the compression algorithm in any manner.
341 350
342 deflate() returns Z_OK if some progress has been made (more input 351 deflate() returns Z_OK if some progress has been made (more input
343 processed or more output produced), Z_STREAM_END if all input has been 352 processed or more output produced), Z_STREAM_END if all input has been
344 consumed and all output has been produced (only when flush is set to 353 consumed and all output has been produced (only when flush is set to
345 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 354 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
346 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible 355 if next_in or next_out was Z_NULL or the state was inadvertently written over
347 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 356 by the application), or Z_BUF_ERROR if no progress is possible (for example
348 fatal, and deflate() can be called again with more input and more output 357 avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and
349 space to continue compressing. 358 deflate() can be called again with more input and more output space to
359 continue compressing.
350*/ 360*/
351 361
352 362
@@ -369,23 +379,20 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
369 379
370 Initializes the internal stream state for decompression. The fields 380 Initializes the internal stream state for decompression. The fields
371 next_in, avail_in, zalloc, zfree and opaque must be initialized before by 381 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
372 the caller. If next_in is not Z_NULL and avail_in is large enough (the 382 the caller. In the current version of inflate, the provide input is not
373 exact value depends on the compression method), inflateInit determines the 383 read or consumed. Any memory allocation will be deferred to the first call
374 compression method from the zlib header and allocates all data structures 384 of inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them
375 accordingly; otherwise the allocation will be deferred to the first call of 385 to use default allocation functions.
376 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
377 use default allocation functions.
378 386
379 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 387 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
380 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 388 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
381 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 389 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
382 invalid, such as a null pointer to the structure. msg is set to null if 390 invalid, such as a null pointer to the structure. msg is set to null if
383 there is no error message. inflateInit does not perform any decompression 391 there is no error message. inflateInit does not perform any decompression.
384 apart from possibly reading the zlib header if present: actual decompression 392 Actual decompression will be done by inflate(). So next_in, and avail_in,
385 will be done by inflate(). (So next_in and avail_in may be modified, but 393 next_out, and avail_out are unused and unchanged. The current
386 next_out and avail_out are unused and unchanged.) The current implementation 394 implementation of inflateInit() does not process any header information --
387 of inflateInit() does not process any header information -- that is deferred 395 that is deferred until inflate() is called.
388 until inflate() is called.
389*/ 396*/
390 397
391 398
@@ -401,17 +408,20 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
401 408
402 - Decompress more input starting at next_in and update next_in and avail_in 409 - Decompress more input starting at next_in and update next_in and avail_in
403 accordingly. If not all input can be processed (because there is not 410 accordingly. If not all input can be processed (because there is not
404 enough room in the output buffer), next_in is updated and processing will 411 enough room in the output buffer), then next_in and avail_on are updated
405 resume at this point for the next call of inflate(). 412 accordingly, and processing will resume at this point for the next call of
413 inflate().
406 414
407 - Provide more output starting at next_out and update next_out and avail_out 415 - Generate more output starting at next_out and update next_out and avail_out
408 accordingly. inflate() provides as much output as possible, until there is 416 accordingly. inflate() provides as much output as possible, until there is
409 no more input data or no more space in the output buffer (see below about 417 no more input data or no more space in the output buffer (see below about
410 the flush parameter). 418 the flush parameter).
411 419
412 Before the call of inflate(), the application should ensure that at least 420 Before the call of inflate(), the application should ensure that at least
413 one of the actions is possible, by providing more input and/or consuming more 421 one of the actions is possible, by providing more input and/or consuming more
414 output, and updating the next_* and avail_* values accordingly. The 422 output, and updating the next_* and avail_* values accordingly. If the
423 caller of inflate() does not provide both available input and available
424 output space, it is possible that there will be no progress made. The
415 application can consume the uncompressed output when it wants, for example 425 application can consume the uncompressed output when it wants, for example
416 when the output buffer is full (avail_out == 0), or after each call of 426 when the output buffer is full (avail_out == 0), or after each call of
417 inflate(). If inflate returns Z_OK and with zero avail_out, it must be 427 inflate(). If inflate returns Z_OK and with zero avail_out, it must be
@@ -428,7 +438,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
428 gets to the end of that block, or when it runs out of data. 438 gets to the end of that block, or when it runs out of data.
429 439
430 The Z_BLOCK option assists in appending to or combining deflate streams. 440 The Z_BLOCK option assists in appending to or combining deflate streams.
431 Also to assist in this, on return inflate() will set strm->data_type to the 441 To assist in this, on return inflate() always sets strm->data_type to the
432 number of unused bits in the last byte taken from strm->next_in, plus 64 if 442 number of unused bits in the last byte taken from strm->next_in, plus 64 if
433 inflate() is currently decoding the last block in the deflate stream, plus 443 inflate() is currently decoding the last block in the deflate stream, plus
434 128 if inflate() returned immediately after decoding an end-of-block code or 444 128 if inflate() returned immediately after decoding an end-of-block code or
@@ -454,7 +464,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
454 this case all pending input is processed and all pending output is flushed; 464 this case all pending input is processed and all pending output is flushed;
455 avail_out must be large enough to hold all of the uncompressed data for the 465 avail_out must be large enough to hold all of the uncompressed data for the
456 operation to complete. (The size of the uncompressed data may have been 466 operation to complete. (The size of the uncompressed data may have been
457 saved by the compressor for this purpose.) The use of Z_FINISH is not 467 saved by the compressor for this purpose.) The use of Z_FINISH is not
458 required to perform an inflation in one step. However it may be used to 468 required to perform an inflation in one step. However it may be used to
459 inform inflate that a faster approach can be used for the single inflate() 469 inform inflate that a faster approach can be used for the single inflate()
460 call. Z_FINISH also informs inflate to not maintain a sliding window if the 470 call. Z_FINISH also informs inflate to not maintain a sliding window if the
@@ -476,32 +486,33 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
476 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 486 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
477 strm->adler to the Adler-32 checksum of all output produced so far (that is, 487 strm->adler to the Adler-32 checksum of all output produced so far (that is,
478 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 488 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
479 below. At the end of the stream, inflate() checks that its computed adler32 489 below. At the end of the stream, inflate() checks that its computed Adler-32
480 checksum is equal to that saved by the compressor and returns Z_STREAM_END 490 checksum is equal to that saved by the compressor and returns Z_STREAM_END
481 only if the checksum is correct. 491 only if the checksum is correct.
482 492
483 inflate() can decompress and check either zlib-wrapped or gzip-wrapped 493 inflate() can decompress and check either zlib-wrapped or gzip-wrapped
484 deflate data. The header type is detected automatically, if requested when 494 deflate data. The header type is detected automatically, if requested when
485 initializing with inflateInit2(). Any information contained in the gzip 495 initializing with inflateInit2(). Any information contained in the gzip
486 header is not retained, so applications that need that information should 496 header is not retained unless inflateGetHeader() is used. When processing
487 instead use raw inflate, see inflateInit2() below, or inflateBack() and
488 perform their own processing of the gzip header and trailer. When processing
489 gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output 497 gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
490 produced so far. The CRC-32 is checked against the gzip trailer. 498 produced so far. The CRC-32 is checked against the gzip trailer, as is the
499 uncompressed length, modulo 2^32.
491 500
492 inflate() returns Z_OK if some progress has been made (more input processed 501 inflate() returns Z_OK if some progress has been made (more input processed
493 or more output produced), Z_STREAM_END if the end of the compressed data has 502 or more output produced), Z_STREAM_END if the end of the compressed data has
494 been reached and all uncompressed output has been produced, Z_NEED_DICT if a 503 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
495 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 504 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
496 corrupted (input stream not conforming to the zlib format or incorrect check 505 corrupted (input stream not conforming to the zlib format or incorrect check
497 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 506 value, in which case strm->msg points to a string with a more specific
498 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, 507 error), Z_STREAM_ERROR if the stream structure was inconsistent (for example
499 Z_BUF_ERROR if no progress is possible or if there was not enough room in the 508 next_in or next_out was Z_NULL, or the state was inadvertently written over
500 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 509 by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR
510 if no progress was possible or if there was not enough room in the output
511 buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
501 inflate() can be called again with more input and more output space to 512 inflate() can be called again with more input and more output space to
502 continue decompressing. If Z_DATA_ERROR is returned, the application may 513 continue decompressing. If Z_DATA_ERROR is returned, the application may
503 then call inflateSync() to look for a good compression block if a partial 514 then call inflateSync() to look for a good compression block if a partial
504 recovery of the data is desired. 515 recovery of the data is to be attempted.
505*/ 516*/
506 517
507 518
@@ -511,9 +522,8 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
511 This function discards any unprocessed input and does not flush any pending 522 This function discards any unprocessed input and does not flush any pending
512 output. 523 output.
513 524
514 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 525 inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state
515 was inconsistent. In the error case, msg may be set but then points to a 526 was inconsistent.
516 static string (which must not be deallocated).
517*/ 527*/
518 528
519 529
@@ -554,14 +564,15 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
554 564
555 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 565 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
556 determines the window size. deflate() will then generate raw deflate data 566 determines the window size. deflate() will then generate raw deflate data
557 with no zlib header or trailer, and will not compute an adler32 check value. 567 with no zlib header or trailer, and will not compute a check value.
558 568
559 windowBits can also be greater than 15 for optional gzip encoding. Add 569 windowBits can also be greater than 15 for optional gzip encoding. Add
560 16 to windowBits to write a simple gzip header and trailer around the 570 16 to windowBits to write a simple gzip header and trailer around the
561 compressed data instead of a zlib wrapper. The gzip header will have no 571 compressed data instead of a zlib wrapper. The gzip header will have no
562 file name, no extra data, no comment, no modification time (set to zero), no 572 file name, no extra data, no comment, no modification time (set to zero), no
563 header crc, and the operating system will be set to 255 (unknown). If a 573 header crc, and the operating system will be set to the appropriate value,
564 gzip stream is being written, strm->adler is a crc32 instead of an adler32. 574 if the operating system was determined at compile time. If a gzip stream is
575 being written, strm->adler is a CRC-32 instead of an Adler-32.
565 576
566 For raw deflate or gzip encoding, a request for a 256-byte window is 577 For raw deflate or gzip encoding, a request for a 256-byte window is
567 rejected as invalid, since only the zlib header provides a means of 578 rejected as invalid, since only the zlib header provides a means of
@@ -626,12 +637,12 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
626 addition, the current implementation of deflate will use at most the window 637 addition, the current implementation of deflate will use at most the window
627 size minus 262 bytes of the provided dictionary. 638 size minus 262 bytes of the provided dictionary.
628 639
629 Upon return of this function, strm->adler is set to the adler32 value 640 Upon return of this function, strm->adler is set to the Adler-32 value
630 of the dictionary; the decompressor may later use this value to determine 641 of the dictionary; the decompressor may later use this value to determine
631 which dictionary has been used by the compressor. (The adler32 value 642 which dictionary has been used by the compressor. (The Adler-32 value
632 applies to the whole dictionary even if only a subset of the dictionary is 643 applies to the whole dictionary even if only a subset of the dictionary is
633 actually used by the compressor.) If a raw deflate was requested, then the 644 actually used by the compressor.) If a raw deflate was requested, then the
634 adler32 value is not computed and strm->adler is not set. 645 Adler-32 value is not computed and strm->adler is not set.
635 646
636 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 647 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
637 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 648 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
@@ -819,7 +830,7 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
819 is for use with other formats that use the deflate compressed data format 830 is for use with other formats that use the deflate compressed data format
820 such as zip. Those formats provide their own check values. If a custom 831 such as zip. Those formats provide their own check values. If a custom
821 format is developed using the raw deflate format for compressed data, it is 832 format is developed using the raw deflate format for compressed data, it is
822 recommended that a check value such as an adler32 or a crc32 be applied to 833 recommended that a check value such as an Adler-32 or a CRC-32 be applied to
823 the uncompressed data as is done in the zlib, gzip, and zip formats. For 834 the uncompressed data as is done in the zlib, gzip, and zip formats. For
824 most applications, the zlib format should be used as is. Note that comments 835 most applications, the zlib format should be used as is. Note that comments
825 above on the use in deflateInit2() applies to the magnitude of windowBits. 836 above on the use in deflateInit2() applies to the magnitude of windowBits.
@@ -828,7 +839,10 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
828 32 to windowBits to enable zlib and gzip decoding with automatic header 839 32 to windowBits to enable zlib and gzip decoding with automatic header
829 detection, or add 16 to decode only the gzip format (the zlib format will 840 detection, or add 16 to decode only the gzip format (the zlib format will
830 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a 841 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
831 crc32 instead of an adler32. 842 CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
843 below), inflate() will not automatically decode concatenated gzip streams.
844 inflate() will return Z_STREAM_END at the end of the gzip stream. The state
845 would need to be reset to continue decoding a subsequent gzip stream.
832 846
833 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 847 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
834 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 848 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
@@ -849,7 +863,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
849 Initializes the decompression dictionary from the given uncompressed byte 863 Initializes the decompression dictionary from the given uncompressed byte
850 sequence. This function must be called immediately after a call of inflate, 864 sequence. This function must be called immediately after a call of inflate,
851 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 865 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
852 can be determined from the adler32 value returned by that call of inflate. 866 can be determined from the Adler-32 value returned by that call of inflate.
853 The compressor and decompressor must use exactly the same dictionary (see 867 The compressor and decompressor must use exactly the same dictionary (see
854 deflateSetDictionary). For raw inflate, this function can be called at any 868 deflateSetDictionary). For raw inflate, this function can be called at any
855 time to set the dictionary. If the provided dictionary is smaller than the 869 time to set the dictionary. If the provided dictionary is smaller than the
@@ -860,7 +874,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
860 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 874 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
861 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 875 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
862 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 876 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
863 expected one (incorrect adler32 value). inflateSetDictionary does not 877 expected one (incorrect Adler-32 value). inflateSetDictionary does not
864 perform any decompression: this will be done by subsequent calls of 878 perform any decompression: this will be done by subsequent calls of
865 inflate(). 879 inflate().
866*/ 880*/
@@ -918,7 +932,7 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
918ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 932ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
919/* 933/*
920 This function is equivalent to inflateEnd followed by inflateInit, 934 This function is equivalent to inflateEnd followed by inflateInit,
921 but does not free and reallocate all the internal decompression state. The 935 but does not free and reallocate the internal decompression state. The
922 stream will keep attributes that may have been set by inflateInit2. 936 stream will keep attributes that may have been set by inflateInit2.
923 937
924 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 938 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
@@ -930,7 +944,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
930/* 944/*
931 This function is the same as inflateReset, but it also permits changing 945 This function is the same as inflateReset, but it also permits changing
932 the wrap and window size requests. The windowBits parameter is interpreted 946 the wrap and window size requests. The windowBits parameter is interpreted
933 the same as it is for inflateInit2. 947 the same as it is for inflateInit2. If the window size is changed, then the
948 memory allocated for the window is freed, and the window will be reallocated
949 by inflate() if needed.
934 950
935 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 951 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
936 stream state was inconsistent (such as zalloc or state being Z_NULL), or if 952 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
@@ -982,7 +998,7 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
982 location in the input stream can be determined from avail_in and data_type 998 location in the input stream can be determined from avail_in and data_type
983 as noted in the description for the Z_BLOCK flush parameter for inflate. 999 as noted in the description for the Z_BLOCK flush parameter for inflate.
984 1000
985 inflateMark returns the value noted above or -65536 if the provided 1001 inflateMark returns the value noted above, or -65536 if the provided
986 source stream state was inconsistent. 1002 source stream state was inconsistent.
987*/ 1003*/
988 1004
@@ -1074,9 +1090,9 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1074 This routine would normally be used in a utility that reads zip or gzip 1090 This routine would normally be used in a utility that reads zip or gzip
1075 files and writes out uncompressed files. The utility would decode the 1091 files and writes out uncompressed files. The utility would decode the
1076 header and process the trailer on its own, hence this routine expects only 1092 header and process the trailer on its own, hence this routine expects only
1077 the raw deflate stream to decompress. This is different from the normal 1093 the raw deflate stream to decompress. This is different from the default
1078 behavior of inflate(), which expects either a zlib or gzip header and 1094 behavior of inflate(), which expects a zlib header and trailer around the
1079 trailer around the deflate stream. 1095 deflate stream.
1080 1096
1081 inflateBack() uses two subroutines supplied by the caller that are then 1097 inflateBack() uses two subroutines supplied by the caller that are then
1082 called by inflateBack() for input and output. inflateBack() calls those 1098 called by inflateBack() for input and output. inflateBack() calls those
@@ -1085,12 +1101,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1085 parameters and return types are defined above in the in_func and out_func 1101 parameters and return types are defined above in the in_func and out_func
1086 typedefs. inflateBack() will call in(in_desc, &buf) which should return the 1102 typedefs. inflateBack() will call in(in_desc, &buf) which should return the
1087 number of bytes of provided input, and a pointer to that input in buf. If 1103 number of bytes of provided input, and a pointer to that input in buf. If
1088 there is no input available, in() must return zero--buf is ignored in that 1104 there is no input available, in() must return zero -- buf is ignored in that
1089 case--and inflateBack() will return a buffer error. inflateBack() will call 1105 case -- and inflateBack() will return a buffer error. inflateBack() will
1090 out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 1106 call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
1091 should return zero on success, or non-zero on failure. If out() returns 1107 out() should return zero on success, or non-zero on failure. If out()
1092 non-zero, inflateBack() will return with an error. Neither in() nor out() 1108 returns non-zero, inflateBack() will return with an error. Neither in() nor
1093 are permitted to change the contents of the window provided to 1109 out() are permitted to change the contents of the window provided to
1094 inflateBackInit(), which is also the buffer that out() uses to write from. 1110 inflateBackInit(), which is also the buffer that out() uses to write from.
1095 The length written by out() will be at most the window size. Any non-zero 1111 The length written by out() will be at most the window size. Any non-zero
1096 amount of input may be provided by in(). 1112 amount of input may be provided by in().
@@ -1118,7 +1134,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1118 using strm->next_in which will be Z_NULL only if in() returned an error. If 1134 using strm->next_in which will be Z_NULL only if in() returned an error. If
1119 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning 1135 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1120 non-zero. (in() will always be called before out(), so strm->next_in is 1136 non-zero. (in() will always be called before out(), so strm->next_in is
1121 assured to be defined if out() returns non-zero.) Note that inflateBack() 1137 assured to be defined if out() returns non-zero.) Note that inflateBack()
1122 cannot return Z_OK. 1138 cannot return Z_OK.
1123*/ 1139*/
1124 1140
@@ -1598,7 +1614,7 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1598 return the updated checksum. If buf is Z_NULL, this function returns the 1614 return the updated checksum. If buf is Z_NULL, this function returns the
1599 required initial value for the checksum. 1615 required initial value for the checksum.
1600 1616
1601 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 1617 An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
1602 much faster. 1618 much faster.
1603 1619
1604 Usage example: 1620 Usage example: