]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix issue with SYNC_FLUSH support by zlib wrapper 291/head
authorDmitry Krot <dak@evanti.ru>
Sat, 13 Aug 2016 19:02:45 +0000 (22:02 +0300)
committerGitHub <noreply@github.com>
Sat, 13 Aug 2016 19:02:45 +0000 (22:02 +0300)
zlibWrapper/zstd_zlibwrapper.c

index 34de73a6df9ada41aa01ac5ed4b42be0eed19c5c..e23a235c9feafb92353db24c90c7b0c869c4ac04 100644 (file)
@@ -227,7 +227,7 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
 
     if (flush == Z_FULL_FLUSH) FINISH_WITH_ERR(strm, "Z_FULL_FLUSH is not supported!");
 
-    if (flush == Z_FINISH || flush == Z_FULL_FLUSH) {
+    if (flush == Z_FINISH) {
         size_t bytesLeft;
         size_t dstCapacity = strm->avail_out;
         if (zwc->bytesLeft) {
@@ -246,6 +246,18 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
         if (flush == Z_FINISH && bytesLeft == 0) return Z_STREAM_END;
         zwc->bytesLeft = bytesLeft;
     }
+    
+    if (flush == Z_SYNC_FLUSH) {
+        size_t bytesLeft;
+        size_t dstCapacity = strm->avail_out;
+        bytesLeft = ZBUFF_compressFlush(zwc->zbc, strm->next_out, &dstCapacity);
+        LOG_WRAPPER("ZBUFF_compressFlush avail_out=%d dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)dstCapacity, (int)bytesLeft);
+        if (ZSTD_isError(bytesLeft)) return Z_MEM_ERROR;
+        strm->next_out += dstCapacity;
+        strm->total_out += dstCapacity;
+        strm->avail_out -= dstCapacity;
+        zwc->bytesLeft = bytesLeft;
+    }
     return Z_OK;
 }