]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Permit a deflateParams() parameter change as soon as possible.
authorMark Adler <madler@alumni.caltech.edu>
Mon, 16 Jan 2017 17:49:35 +0000 (09:49 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 15 Jan 2019 10:02:02 +0000 (11:02 +0100)
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.

deflate.c
zlib-ng.h
zlib.h

index 64d870f0ddb2035d4ed6c0b7758fbaa461e0163a..fc48a31d73eb721b50ed7071b52d7d37d242d212 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -510,7 +510,7 @@ int ZEXPORT PREFIX(deflateResetKeep)(PREFIX3(stream) *strm) {
     else
 #endif
         strm->adler = functable.adler32(0L, NULL, 0);
-    s->last_flush = Z_NO_FLUSH;
+    s->last_flush = -2;
 
     _tr_init(s);
 
@@ -586,12 +586,13 @@ int ZEXPORT PREFIX(deflateParams)(PREFIX3(stream) *strm, int level, int strategy
     }
     func = configuration_table[s->level].func;
 
-    if ((strategy != s->strategy || func != configuration_table[level].func) && s->high_water) {
+    if ((strategy != s->strategy || func != configuration_table[level].func) &&
+        s->last_flush != -2) {
         /* Flush the last buffer: */
         int err = PREFIX(deflate)(strm, Z_BLOCK);
         if (err == Z_STREAM_ERROR)
             return err;
-        if (strm->avail_out == 0)
+        if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
             return Z_BUF_ERROR;
     }
     if (s->level != level) {
index 3a52d1f234ca05cda15df8f43dd3a5126d1383ec..3d972a0c5e672d6bfee37e8321d6e44e1de81aea 100644 (file)
--- a/zlib-ng.h
+++ b/zlib-ng.h
@@ -693,11 +693,12 @@ ZEXTERN int ZEXPORT zng_deflateParams(zng_stream *strm, int level, int strategy)
    used to switch between compression and straight copy of the input data, or
    to switch to a different kind of input data requiring a different strategy.
    If the compression approach (which is a function of the level) or the
-   strategy is changed, and if any input has been consumed in a previous
-   deflate() call, then the input available so far is compressed with the old
-   level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
-   for the compression levels 0, 1..3, and 4..9 respectively.  The new level
-   and strategy will take effect at the next call of deflate().
+   strategy is changed, and if there have been any deflate() calls since the
+   state was initialized or reset, then the input available so far is
+   compressed with the old level and strategy using deflate(strm, Z_BLOCK).
+   There are three approaches for the compression levels 0, 1..3, and 4..9
+   respectively.  The new level and strategy will take effect at the next call
+   of deflate().
 
      If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
    not have enough output space to complete, then the parameter change will not
diff --git a/zlib.h b/zlib.h
index afe71ea1a26669b56d04f51ae302f41b0351269a..891350013992a1bbc17606a957f87c338bd65a7e 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -704,11 +704,12 @@ ZEXTERN int ZEXPORT deflateParams(z_stream *strm, int level, int strategy);
    used to switch between compression and straight copy of the input data, or
    to switch to a different kind of input data requiring a different strategy.
    If the compression approach (which is a function of the level) or the
-   strategy is changed, and if any input has been consumed in a previous
-   deflate() call, then the input available so far is compressed with the old
-   level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
-   for the compression levels 0, 1..3, and 4..9 respectively.  The new level
-   and strategy will take effect at the next call of deflate().
+   strategy is changed, and if there have been any deflate() calls since the
+   state was initialized or reset, then the input available so far is
+   compressed with the old level and strategy using deflate(strm, Z_BLOCK).
+   There are three approaches for the compression levels 0, 1..3, and 4..9
+   respectively.  The new level and strategy will take effect at the next call
+   of deflate().
 
      If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
    not have enough output space to complete, then the parameter change will not