improved inflateSync
diff --git a/zlibWrapper/README.md b/zlibWrapper/README.md
index 3a39f00..5ea542f 100644
--- a/zlibWrapper/README.md
+++ b/zlibWrapper/README.md
@@ -95,6 +95,7 @@
- deflateSetHeader
- inflateGetDictionary
- inflateCopy
+- inflateSync
- inflateReset
- inflateReset2
- inflatePrime
diff --git a/zlibWrapper/zstd_zlibwrapper.c b/zlibWrapper/zstd_zlibwrapper.c
index bb5bd92..3ed842c 100644
--- a/zlibWrapper/zstd_zlibwrapper.c
+++ b/zlibWrapper/zstd_zlibwrapper.c
@@ -160,6 +160,14 @@
}
+ZEXTERN int ZEXPORT z_deflateReset OF((z_streamp strm))
+{
+ if (!g_useZSTD)
+ return deflateReset(strm);
+ FINISH_WITH_ERR(strm, "deflateReset is not supported!");
+}
+
+
ZEXTERN int ZEXPORT z_deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength))
@@ -217,7 +225,7 @@
strm->avail_in -= zwc->inBuffer.pos;
}
- if (flush == Z_FULL_FLUSH) FINISH_WITH_ERR(strm, "Z_FULL_FLUSH is not supported!");
+ if (flush == Z_FULL_FLUSH || flush == Z_BLOCK || flush == Z_TREES) FINISH_WITH_ERR(strm, "Z_FULL_FLUSH, Z_BLOCK and Z_TREES are not supported!");
if (flush == Z_FINISH) {
size_t bytesLeft;
@@ -233,7 +241,7 @@
if (bytesLeft == 0) return Z_STREAM_END;
}
else
- if (flush == Z_SYNC_FLUSH) {
+ if (flush == Z_SYNC_FLUSH || flush == Z_PARTIAL_FLUSH) {
size_t bytesLeft;
zwc->outBuffer.dst = strm->next_out;
zwc->outBuffer.size = strm->avail_out;
@@ -486,6 +494,8 @@
errorCode = ZSTD_initDStream(zwd->zbd);
if (ZSTD_isError(errorCode)) goto error;
+ if (flush == Z_INFLATE_SYNC) { strm->msg = "inflateSync is not supported!"; goto error; }
+
inPos = zwd->inBuffer.pos;
zwd->inBuffer.src = zwd->headerBuf;
zwd->inBuffer.size = ZSTD_HEADERSIZE;
@@ -553,6 +563,9 @@
ZEXTERN int ZEXPORT z_inflateSync OF((z_streamp strm))
{
+ if (!strm->reserved)
+ return z_inflateSync(strm);
+
return z_inflate(strm, Z_INFLATE_SYNC);
}
@@ -569,14 +582,6 @@
}
-ZEXTERN int ZEXPORT z_deflateReset OF((z_streamp strm))
-{
- if (!g_useZSTD)
- return deflateReset(strm);
- FINISH_WITH_ERR(strm, "deflateReset is not supported!");
-}
-
-
ZEXTERN int ZEXPORT z_deflateTune OF((z_streamp strm,
int good_length,
int max_lazy,
@@ -622,7 +627,7 @@
-/* Advanced compression functions */
+/* Advanced decompression functions */
#if ZLIB_VERNUM >= 0x1280
ZEXTERN int ZEXPORT z_inflateGetDictionary OF((z_streamp strm,
Bytef *dictionary,