aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2017-01-16 09:49:35 -0800
committerMark Adler <madler@alumni.caltech.edu>2017-02-15 22:38:55 -0800
commitf9694097dd69354b03cb8af959094c7f260db0a1 (patch)
tree3077a3e9e3eb1de0bb1fb65b439f1701c9ea91d6
parent5ff989033e8b839b80ce716a1452acf7664e2ff4 (diff)
downloadzlib-f9694097dd69354b03cb8af959094c7f260db0a1.tar.gz
zlib-f9694097dd69354b03cb8af959094c7f260db0a1.tar.bz2
zlib-f9694097dd69354b03cb8af959094c7f260db0a1.zip
Permit a deflateParams() parameter change as soon as possible.
This commit allows a parameter change even if the input data has not all been compressed and copied to the application output buffer, so long as all of the input data has been compressed to the internal pending output buffer. This also allows an immediate deflateParams change so long as there have been no deflate calls since initialization or reset.
-rw-r--r--deflate.c6
-rw-r--r--zlib.h11
2 files changed, 9 insertions, 8 deletions
diff --git a/deflate.c b/deflate.c
index b63311a..20bda4f 100644
--- a/deflate.c
+++ b/deflate.c
@@ -494,7 +494,7 @@ int ZEXPORT deflateResetKeep (strm)
494 s->wrap == 2 ? crc32(0L, Z_NULL, 0) : 494 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
495#endif 495#endif
496 adler32(0L, Z_NULL, 0); 496 adler32(0L, Z_NULL, 0);
497 s->last_flush = Z_NO_FLUSH; 497 s->last_flush = -2;
498 498
499 _tr_init(s); 499 _tr_init(s);
500 500
@@ -587,12 +587,12 @@ int ZEXPORT deflateParams(strm, level, strategy)
587 func = configuration_table[s->level].func; 587 func = configuration_table[s->level].func;
588 588
589 if ((strategy != s->strategy || func != configuration_table[level].func) && 589 if ((strategy != s->strategy || func != configuration_table[level].func) &&
590 s->high_water) { 590 s->last_flush != -2) {
591 /* Flush the last buffer: */ 591 /* Flush the last buffer: */
592 int err = deflate(strm, Z_BLOCK); 592 int err = deflate(strm, Z_BLOCK);
593 if (err == Z_STREAM_ERROR) 593 if (err == Z_STREAM_ERROR)
594 return err; 594 return err;
595 if (strm->avail_out == 0) 595 if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
596 return Z_BUF_ERROR; 596 return Z_BUF_ERROR;
597 } 597 }
598 if (s->level != level) { 598 if (s->level != level) {
diff --git a/zlib.h b/zlib.h
index 5daf4f2..577d81e 100644
--- a/zlib.h
+++ b/zlib.h
@@ -712,11 +712,12 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
712 used to switch between compression and straight copy of the input data, or 712 used to switch between compression and straight copy of the input data, or
713 to switch to a different kind of input data requiring a different strategy. 713 to switch to a different kind of input data requiring a different strategy.
714 If the compression approach (which is a function of the level) or the 714 If the compression approach (which is a function of the level) or the
715 strategy is changed, and if any input has been consumed in a previous 715 strategy is changed, and if there have been any deflate() calls since the
716 deflate() call, then the input available so far is compressed with the old 716 state was initialized or reset, then the input available so far is
717 level and strategy using deflate(strm, Z_BLOCK). There are three approaches 717 compressed with the old level and strategy using deflate(strm, Z_BLOCK).
718 for the compression levels 0, 1..3, and 4..9 respectively. The new level 718 There are three approaches for the compression levels 0, 1..3, and 4..9
719 and strategy will take effect at the next call of deflate(). 719 respectively. The new level and strategy will take effect at the next call
720 of deflate().
720 721
721 If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does 722 If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
722 not have enough output space to complete, then the parameter change will not 723 not have enough output space to complete, then the parameter change will not