]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Permit immediate deflateParams changes before any deflate input.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 15 Jan 2017 16:22:16 +0000 (08:22 -0800)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 13 Feb 2017 09:12:11 +0000 (10:12 +0100)
This permits deflateParams to change the strategy and level right
after deflateInit, without having to wait until a header has been
written. The parameters can be changed immediately up until the
first deflate call that consumes any input data.

deflate.c
zlib.h

index 456e5e805f5fd2516b845985e3166d6d15a2582b..99e59d6da426528b7ff268b8161cec2d7d6c52f6 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -539,7 +539,7 @@ int ZEXPORT deflateParams(z_stream *strm, int level, int strategy) {
     }
     func = configuration_table[s->level].func;
 
-    if ((strategy != s->strategy || func != configuration_table[level].func)) {
+    if ((strategy != s->strategy || func != configuration_table[level].func) && s->high_water) {
         /* Flush the last buffer: */
         int err = deflate(strm, Z_BLOCK);
         if (err == Z_STREAM_ERROR)
diff --git a/zlib.h b/zlib.h
index ab0b41dd32bcfb40523ee1f0380e5e78fc4fdfe3..119b392668017cbbd5717976f0968a9d86a9bff9 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -704,10 +704,11 @@ 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, 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 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().
 
      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