diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-12-08 19:03:56 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-12-10 22:33:24 -0800 |
commit | 421c7a61f08ff255bf898f0e687b7d7c8fbdae77 (patch) | |
tree | 7abc5d3f6fe5120c1afbe468211c10ab9a763901 /zlib.h | |
parent | fb00fda903bbd128952a8ecac4b4f6b459245012 (diff) | |
download | zlib-421c7a61f08ff255bf898f0e687b7d7c8fbdae77.tar.gz zlib-421c7a61f08ff255bf898f0e687b7d7c8fbdae77.tar.bz2 zlib-421c7a61f08ff255bf898f0e687b7d7c8fbdae77.zip |
Have inflate() with Z_FINISH avoid the allocation of a window.
inflate() avoided that allocation normally, until it was modified to
update the window on a normal completion so that inflateResetKeep()
could work. This patch restores that behavior, but only when
Z_FINISH is used successfully to complete an inflation of a stream in
a single call of inflate(). The comments in zlib.h have been updated
accordingly.
Diffstat (limited to 'zlib.h')
-rw-r--r-- | zlib.h | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -455,20 +455,23 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); | |||
455 | avail_out must be large enough to hold all the uncompressed data. (The size | 455 | avail_out must be large enough to hold all the uncompressed data. (The size |
456 | of the uncompressed data may have been saved by the compressor for this | 456 | of the uncompressed data may have been saved by the compressor for this |
457 | purpose.) The next operation on this stream must be inflateEnd to deallocate | 457 | purpose.) The next operation on this stream must be inflateEnd to deallocate |
458 | the decompression state. The use of Z_FINISH is never required, but can be | 458 | the decompression state. The use of Z_FINISH is not required to perform an |
459 | used to inform inflate that a faster approach may be used for the single | 459 | inflation in one step. However it may be used to inform inflate that a |
460 | inflate() call. | 460 | faster approach can be used for the single inflate() call. Z_FINISH also |
461 | informs inflate to not maintain a sliding window if the stream completes, | ||
462 | which reduces inflate's memory footprint. | ||
461 | 463 | ||
462 | In this implementation, inflate() always flushes as much output as | 464 | In this implementation, inflate() always flushes as much output as |
463 | possible to the output buffer, and always uses the faster approach on the | 465 | possible to the output buffer, and always uses the faster approach on the |
464 | first call. So the only effect of the flush parameter in this implementation | 466 | first call. So the effects of the flush parameter in this implementation are |
465 | is on the return value of inflate(), as noted below, or when it returns early | 467 | on the return value of inflate() as noted below, when inflate() returns early |
466 | because Z_BLOCK or Z_TREES is used. | 468 | when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of |
469 | memory for a sliding window when Z_FINISH is used. | ||
467 | 470 | ||
468 | If a preset dictionary is needed after this call (see inflateSetDictionary | 471 | If a preset dictionary is needed after this call (see inflateSetDictionary |
469 | below), inflate sets strm->adler to the adler32 checksum of the dictionary | 472 | below), inflate sets strm->adler to the Adler-32 checksum of the dictionary |
470 | chosen by the compressor and returns Z_NEED_DICT; otherwise it sets | 473 | chosen by the compressor and returns Z_NEED_DICT; otherwise it sets |
471 | strm->adler to the adler32 checksum of all output produced so far (that is, | 474 | strm->adler to the Adler-32 checksum of all output produced so far (that is, |
472 | total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described | 475 | total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described |
473 | below. At the end of the stream, inflate() checks that its computed adler32 | 476 | below. At the end of the stream, inflate() checks that its computed adler32 |
474 | checksum is equal to that saved by the compressor and returns Z_STREAM_END | 477 | checksum is equal to that saved by the compressor and returns Z_STREAM_END |
@@ -479,7 +482,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); | |||
479 | initializing with inflateInit2(). Any information contained in the gzip | 482 | initializing with inflateInit2(). Any information contained in the gzip |
480 | header is not retained, so applications that need that information should | 483 | header is not retained, so applications that need that information should |
481 | instead use raw inflate, see inflateInit2() below, or inflateBack() and | 484 | instead use raw inflate, see inflateInit2() below, or inflateBack() and |
482 | perform their own processing of the gzip header and trailer. | 485 | perform their own processing of the gzip header and trailer. When processing |
486 | gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output | ||
487 | producted so far. The CRC-32 is checked against the gzip trailer. | ||
483 | 488 | ||
484 | inflate() returns Z_OK if some progress has been made (more input processed | 489 | inflate() returns Z_OK if some progress has been made (more input processed |
485 | or more output produced), Z_STREAM_END if the end of the compressed data has | 490 | or more output produced), Z_STREAM_END if the end of the compressed data has |