]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
improved logging
authorinikep <inikep@gmail.com>
Tue, 20 Sep 2016 13:18:00 +0000 (15:18 +0200)
committerinikep <inikep@gmail.com>
Tue, 20 Sep 2016 13:18:00 +0000 (15:18 +0200)
zlibWrapper/Makefile
zlibWrapper/examples/example.c
zlibWrapper/examples/fitblk.c
zlibWrapper/zstd_zlibwrapper.c

index ed296931e6ddf4d26f535517fcd51b6102b90caf..f966b4523682dfda3058eb3f96cd8780505fc09a 100644 (file)
@@ -37,6 +37,7 @@ testzstd: example_zstd
 
 testfitblk: fitblk
        ./fitblk 10240 <../zstd_compression_format.md
+       #./fitblk 40960 <../zstd_compression_format.md
 
 .c.o:
        $(CC) $(CFLAGS) -c -o $@ $<
index bbb2cd5a3a7586939eb74e5172d70ac6c6500b39..c1f3b46b39ac624e762f45a5fcb0f994e46784b2 100644 (file)
     } \
 }
 
-z_const char hello[] = "hello, hello!";
+z_const char hello[] = "hello, hello! I said hello, hello!";
 /* "hello world" would be more standard, but the repeated "hello"
  * stresses the compression code better, sorry...
  */
 
-const char dictionary[] = "hello";
+const char dictionary[] = "hello, hello!";
 uLong dictId; /* Adler32 value of the dictionary */
 
 void test_deflate       OF((Byte *compr, uLong comprLen));
@@ -156,7 +156,7 @@ void test_gzio(fname, uncompr, uncomprLen)
         fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
         exit(1);
     }
-    if (gzprintf(file, ", %s!", "hello") != 8) {
+    if (gzprintf(file, ", %s! I said hello, hello!", "hello") != 8+21) {
         fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
         exit(1);
     }
@@ -182,7 +182,7 @@ void test_gzio(fname, uncompr, uncomprLen)
     }
 
     pos = gzseek(file, -8L, SEEK_CUR);
-    if (pos != 6 || gztell(file) != pos) {
+    if (pos != 6+21 || gztell(file) != pos) {
         fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
                 (long)pos, (long)gztell(file));
         exit(1);
@@ -203,7 +203,7 @@ void test_gzio(fname, uncompr, uncomprLen)
         fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
         exit(1);
     }
-    if (strcmp((char*)uncompr, hello + 6)) {
+    if (strcmp((char*)uncompr, hello + 6+21)) {
         fprintf(stderr, "bad gzgets after gzseek\n");
         exit(1);
     } else {
index 35b067b44d259858481f9eefc4ff2bdbc914dd6a..1f12187bde835cb8e4d7097e4310b6f2bf275396 100644 (file)
@@ -76,18 +76,19 @@ local int partcompress(FILE *in, z_streamp def)
     int ret, flush;
     unsigned char raw[RAWLEN];
 
-    flush = Z_NO_FLUSH;
+    flush = Z_SYNC_FLUSH;
     do {
         def->avail_in = fread(raw, 1, RAWLEN, in);
-        printf("def->avail_in=%d\n", def->avail_in);
+        printf("partcompress def->avail_in=%d\n", def->avail_in);
         if (ferror(in))
             return Z_ERRNO;
         def->next_in = raw;
         if (feof(in))
             flush = Z_FINISH;
         ret = deflate(def, flush);
+        printf("partcompress def->avail_out=%d\n", def->avail_out);
         assert(ret != Z_STREAM_ERROR);
-    } while (def->avail_out != 0 && flush == Z_NO_FLUSH);
+    } while (def->avail_out != 0 && flush == Z_SYNC_FLUSH);
     return ret;
 }
 
@@ -104,7 +105,7 @@ local int recompress(z_streamp inf, z_streamp def)
     do {
         /* decompress */
         inf->avail_out = RAWLEN;
-        printf("inf->avail_out=%d\n", inf->avail_out);
+        printf("recompress inf->avail_out=%d\n", inf->avail_out);
 
         inf->next_out = raw;
         ret = inflate(inf, Z_NO_FLUSH);
@@ -120,6 +121,7 @@ local int recompress(z_streamp inf, z_streamp def)
             flush = Z_FINISH;
         ret = deflate(def, flush);
         assert(ret != Z_STREAM_ERROR);
+        printf("recompress def->avail_out=%d ret=%d\n", def->avail_out, ret);
     } while (ret != Z_STREAM_END && def->avail_out != 0);
     return ret;
 }
@@ -167,7 +169,7 @@ int main(int argc, char **argv)
     if (ret == Z_ERRNO)
         quit("error reading input");
 
-printf("partcompress def.avail_out=%d\n", def.avail_out);
+printf("partcompress def.total_out=%d ret=%d\n", (int)def.total_out, ret);
     /* if it all fit, then size was undersubscribed -- done! */
     if (ret == Z_STREAM_END && def.avail_out >= EXCESS) {
         /* write block to stdout */
index d842ae75fecde1248f54259beac56884b802c7b9..28f42526efb688f6612f54d0f9ded3ef95c14949 100644 (file)
@@ -22,7 +22,8 @@
 #define ZSTD_HEADERSIZE             ZSTD_frameHeaderSize_min
 #define ZWRAP_DEFAULT_CLEVEL        5   /* Z_DEFAULT_COMPRESSION is translated to ZWRAP_DEFAULT_CLEVEL for zstd */
 
-#define LOG_WRAPPER(...)  /* printf(__VA_ARGS__) */
+#define LOG_WRAPPERC(...)   /*printf(__VA_ARGS__)*/ 
+#define LOG_WRAPPERD(...)   /*printf(__VA_ARGS__)*/ 
 
 
 #define FINISH_WITH_GZ_ERR(msg) { \
@@ -122,6 +123,7 @@ ZWRAP_CCtx* ZWRAP_createCCtx(z_streamp strm)
 
 int ZWRAPC_finish_with_error(ZWRAP_CCtx* zwc, z_streamp strm, int error)
 {
+    LOG_WRAPPERC("- ZWRAPC_finish_with_error=%d\n", error);
     if (zwc) ZWRAP_freeCCtx(zwc);
     if (strm) strm->state = NULL;
     return (error) ? error : Z_STREAM_ERROR;
@@ -133,12 +135,11 @@ ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
 {
     ZWRAP_CCtx* zwc;
 
+    LOG_WRAPPERC("- deflateInit level=%d\n", level);
     if (!g_useZSTD) {
-        LOG_WRAPPER("- deflateInit level=%d\n", level);
         return deflateInit_((strm), (level), version, stream_size);
     }
 
-    LOG_WRAPPER("- deflateInit level=%d\n", level);
     zwc = ZWRAP_createCCtx(strm);
     if (zwc == NULL) return Z_MEM_ERROR;
 
@@ -170,11 +171,11 @@ ZEXTERN int ZEXPORT z_deflateInit2_ OF((z_streamp strm, int level, int method,
 
 ZEXTERN int ZEXPORT z_deflateReset OF((z_streamp strm))
 {
+    LOG_WRAPPERC("- deflateReset\n");
     if (!g_useZSTD)
         return deflateReset(strm);
 
     {   ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
-        LOG_WRAPPER("- z_deflateReset\n");
         if (zwc == NULL) return Z_STREAM_ERROR;
         { size_t const errorCode = ZSTD_resetCStream(zwc->zbc, 0);
           if (ZSTD_isError(errorCode)) return ZWRAPC_finish_with_error(zwc, strm, 0); }
@@ -190,11 +191,13 @@ ZEXTERN int ZEXPORT z_deflateSetDictionary OF((z_streamp strm,
                                              const Bytef *dictionary,
                                              uInt  dictLength))
 {
-    if (!g_useZSTD)
+    if (!g_useZSTD) {
+        LOG_WRAPPERC("- deflateSetDictionary\n");
         return deflateSetDictionary(strm, dictionary, dictLength);
+    }
 
     {   ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
-        LOG_WRAPPER("- deflateSetDictionary level=%d\n", (int)zwc->compressionLevel);
+        LOG_WRAPPERC("- deflateSetDictionary level=%d\n", (int)zwc->compressionLevel);
         if (zwc == NULL) return Z_STREAM_ERROR;
         { size_t const errorCode = ZSTD_initCStream_usingDict(zwc->zbc, dictionary, dictLength, zwc->compressionLevel);
           if (ZSTD_isError(errorCode)) return ZWRAPC_finish_with_error(zwc, strm, 0); }
@@ -209,15 +212,17 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
     ZWRAP_CCtx* zwc;
 
     if (!g_useZSTD) {
-        int res = deflate(strm, flush);
-        LOG_WRAPPER("- avail_in=%d total_in=%d total_out=%d\n", (int)strm->avail_in, (int)strm->total_in, (int)strm->total_out);
+        int res;
+        LOG_WRAPPERC("- deflate1 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
+        res = deflate(strm, flush);
+        LOG_WRAPPERC("- deflate2 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
         return res;
     }
 
     zwc = (ZWRAP_CCtx*) strm->state;
     if (zwc == NULL) return Z_STREAM_ERROR;
 
-    LOG_WRAPPER("deflate flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
+    LOG_WRAPPERC("- deflate1 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
     if (strm->avail_in > 0) {
         zwc->inBuffer.src = strm->next_in;
         zwc->inBuffer.size = strm->avail_in;
@@ -226,7 +231,7 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
         zwc->outBuffer.size = strm->avail_out;
         zwc->outBuffer.pos = 0;
         { size_t const errorCode = ZSTD_compressStream(zwc->zbc, &zwc->outBuffer, &zwc->inBuffer);
-          LOG_WRAPPER("ZSTD_compressStream srcSize=%d dstCapacity=%d\n", (int)zwc->inBuffer.size, (int)zwc->outBuffer.size);
+          LOG_WRAPPERC("deflate ZSTD_compressStream srcSize=%d dstCapacity=%d\n", (int)zwc->inBuffer.size, (int)zwc->outBuffer.size);
           if (ZSTD_isError(errorCode)) return ZWRAPC_finish_with_error(zwc, strm, 0);
         }
         strm->next_out += zwc->outBuffer.pos;
@@ -245,12 +250,12 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
         zwc->outBuffer.size = strm->avail_out;
         zwc->outBuffer.pos = 0;
         bytesLeft = ZSTD_endStream(zwc->zbc, &zwc->outBuffer);
-        LOG_WRAPPER("ZSTD_endStream dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)bytesLeft);
+        LOG_WRAPPERC("deflate ZSTD_endStream dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)bytesLeft);
         if (ZSTD_isError(bytesLeft)) return ZWRAPC_finish_with_error(zwc, strm, 0);
         strm->next_out += zwc->outBuffer.pos;
         strm->total_out += zwc->outBuffer.pos;
         strm->avail_out -= zwc->outBuffer.pos;
-        if (bytesLeft == 0) return Z_STREAM_END;
+        if (bytesLeft == 0) { LOG_WRAPPERC("Z_STREAM_END2 strm->total_in=%d strm->avail_out=%d strm->total_out=%d\n", (int)strm->total_in, (int)strm->avail_out, (int)strm->total_out); return Z_STREAM_END; }
     }
     else
     if (flush == Z_SYNC_FLUSH || flush == Z_PARTIAL_FLUSH) {
@@ -259,12 +264,13 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
         zwc->outBuffer.size = strm->avail_out;
         zwc->outBuffer.pos = 0;
         bytesLeft = ZSTD_flushStream(zwc->zbc, &zwc->outBuffer);
-        LOG_WRAPPER("ZSTD_flushStream dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)bytesLeft);
+        LOG_WRAPPERC("deflate ZSTD_flushStream dstCapacity=%d bytesLeft=%d\n", (int)strm->avail_out, (int)bytesLeft);
         if (ZSTD_isError(bytesLeft)) return ZWRAPC_finish_with_error(zwc, strm, 0);
         strm->next_out += zwc->outBuffer.pos;
         strm->total_out += zwc->outBuffer.pos;
         strm->avail_out -= zwc->outBuffer.pos;
     }
+    LOG_WRAPPERC("- deflate2 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
     return Z_OK;
 }
 
@@ -272,10 +278,10 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
 ZEXTERN int ZEXPORT z_deflateEnd OF((z_streamp strm))
 {
     if (!g_useZSTD) {
-        LOG_WRAPPER("- deflateEnd\n");
+        LOG_WRAPPERC("- deflateEnd\n");
         return deflateEnd(strm);
     }
-    LOG_WRAPPER("- deflateEnd total_in=%d total_out=%d\n", (int)(strm->total_in), (int)(strm->total_out));
+    LOG_WRAPPERC("- deflateEnd total_in=%d total_out=%d\n", (int)(strm->total_in), (int)(strm->total_out));
     {   ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state;
         size_t const errorCode = ZWRAP_freeCCtx(zwc);
         strm->state = NULL;
@@ -300,7 +306,7 @@ ZEXTERN int ZEXPORT z_deflateParams OF((z_streamp strm,
                                       int strategy))
 {
     if (!g_useZSTD) {
-        LOG_WRAPPER("- deflateParams level=%d strategy=%d\n", level, strategy);
+        LOG_WRAPPERC("- deflateParams level=%d strategy=%d\n", level, strategy);
         return deflateParams(strm, level, strategy);
     }
 
@@ -366,6 +372,7 @@ size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd)
 
 int ZWRAPD_finish_with_error(ZWRAP_DCtx* zwd, z_streamp strm, int error)
 {
+    LOG_WRAPPERD("- ZWRAPD_finish_with_error=%d\n", error);
     if (zwd) ZWRAP_freeDCtx(zwd);
     if (strm) strm->state = NULL;
     return (error) ? error : Z_STREAM_ERROR;
@@ -376,7 +383,7 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
                                      const char *version, int stream_size))
 {
     ZWRAP_DCtx* zwd = ZWRAP_createDCtx(strm);
-    LOG_WRAPPER("- inflateInit\n");
+    LOG_WRAPPERD("- inflateInit\n");
     if (zwd == NULL) return ZWRAPD_finish_with_error(zwd, strm, 0);
 
     zwd->version = zwd->customMem.customAlloc(zwd->customMem.opaque, strlen(version) + 1);
@@ -407,10 +414,16 @@ ZEXTERN int ZEXPORT z_inflateInit2_ OF((z_streamp strm, int  windowBits,
 
 ZEXTERN int ZEXPORT z_inflateReset OF((z_streamp strm))
 {
+    LOG_WRAPPERD("- inflateReset\n");
     if (!strm->reserved)
         return inflateReset(strm);
 
-    FINISH_WITH_ERR(strm, "inflateReset is not supported!");
+    {   ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
+        if (zwd == NULL) return Z_STREAM_ERROR;
+        { size_t const errorCode = ZSTD_resetDStream(zwd->zbd);
+          if (ZSTD_isError(errorCode)) return ZWRAPD_finish_with_error(zwd, strm, 0); }
+    }
+    
     strm->total_in = 0;
     strm->total_out = 0;
     return Z_OK;
@@ -421,10 +434,10 @@ ZEXTERN int ZEXPORT z_inflateSetDictionary OF((z_streamp strm,
                                              const Bytef *dictionary,
                                              uInt  dictLength))
 {
+    LOG_WRAPPERD("- inflateSetDictionary\n");
     if (!strm->reserved)
         return inflateSetDictionary(strm, dictionary, dictLength);
 
-    LOG_WRAPPER("- inflateSetDictionary\n");
     {   size_t errorCode;
         ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
         if (strm->state == NULL) return Z_STREAM_ERROR;
@@ -439,9 +452,9 @@ ZEXTERN int ZEXPORT z_inflateSetDictionary OF((z_streamp strm,
             zwd->outBuffer.size = 0;
             zwd->outBuffer.pos = 0;
             errorCode = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer);
-            LOG_WRAPPER("ZSTD_decompressStream3 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size);
+            LOG_WRAPPERD("inflateSetDictionary ZSTD_decompressStream errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size);
             if (zwd->inBuffer.pos < zwd->outBuffer.size || ZSTD_isError(errorCode)) {
-                LOG_WRAPPER("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
+                LOG_WRAPPERD("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
                 return ZWRAPD_finish_with_error(zwd, strm, 0);
             }
         }
@@ -453,14 +466,19 @@ ZEXTERN int ZEXPORT z_inflateSetDictionary OF((z_streamp strm,
 
 ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
 {
-    if (!strm->reserved)
-        return inflate(strm, flush);
+    int res;
+    if (!strm->reserved) {
+        LOG_WRAPPERD("- inflate1 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
+        res = inflate(strm, flush);
+        LOG_WRAPPERD("- inflate2 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
+        return res;
+    }
 
     if (strm->avail_in > 0) {
         size_t errorCode, srcSize, inPos;
         ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
         if (strm->state == NULL) return Z_STREAM_ERROR;
-        LOG_WRAPPER("inflate avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
+        LOG_WRAPPERD("- inflate1 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
      //   if (((strm->avail_in < ZSTD_HEADERSIZE) || (strm->total_in > 0)) && (strm->total_in < ZLIB_HEADERSIZE))
         if (strm->total_in < ZLIB_HEADERSIZE)
         {
@@ -483,7 +501,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
                     errorCode = inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size);
                 else
                     errorCode = inflateInit_(strm, zwd->version, zwd->stream_size);
-                LOG_WRAPPER("ZLIB inflateInit errorCode=%d\n", (int)errorCode);
+                LOG_WRAPPERD("ZLIB inflateInit errorCode=%d\n", (int)errorCode);
                 if (errorCode != Z_OK) return ZWRAPD_finish_with_error(zwd, strm, (int)errorCode);
 
                 /* inflate header */
@@ -491,7 +509,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
                 strm->avail_in = ZLIB_HEADERSIZE;
                 strm->avail_out = 0;
                 errorCode = inflate(strm, Z_NO_FLUSH);
-                LOG_WRAPPER("ZLIB inflate errorCode=%d strm->avail_in=%d\n", (int)errorCode, (int)strm->avail_in);
+                LOG_WRAPPERD("ZLIB inflate errorCode=%d strm->avail_in=%d\n", (int)errorCode, (int)strm->avail_in);
                 if (errorCode != Z_OK) return ZWRAPD_finish_with_error(zwd, strm, (int)errorCode);
                 if (strm->avail_in > 0) goto error;
 
@@ -504,8 +522,10 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
                 errorCode = ZWRAP_freeDCtx(zwd);
                 if (ZSTD_isError(errorCode)) goto error;
 
-                if (flush == Z_INFLATE_SYNC) return inflateSync(strm);
-                return inflate(strm, flush);
+                if (flush == Z_INFLATE_SYNC) res = inflateSync(strm);
+                else res = inflate(strm, flush);
+                LOG_WRAPPERD("- inflate2 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
+                return res;
             }
         }
 
@@ -536,13 +556,13 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
             zwd->outBuffer.size = 0;
             zwd->outBuffer.pos = 0;
             errorCode = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer);
-            LOG_WRAPPER("ZSTD_decompressStream1 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size);
+            LOG_WRAPPERD("inflate ZSTD_decompressStream1 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)zwd->inBuffer.size, (int)zwd->outBuffer.size);
             if (ZSTD_isError(errorCode)) {
-                LOG_WRAPPER("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
+                LOG_WRAPPERD("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
                 goto error;
             }
-          //  LOG_WRAPPER("1srcSize=%d inpos=%d inBuffer.pos=%d inBuffer.size=%d outBuffer.pos=%d\n", (int)srcSize, (int)inPos, (int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos);
-            if (zwd->inBuffer.pos == zwd->inBuffer.size) return Z_OK;
+          //  LOG_WRAPPERD("1srcSize=%d inpos=%d inBuffer.pos=%d inBuffer.size=%d outBuffer.pos=%d\n", (int)srcSize, (int)inPos, (int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos);
+            if (zwd->inBuffer.pos != zwd->inBuffer.size) return ZWRAPD_finish_with_error(zwd, strm, 0); /* not consumed */
         }
 
         inPos = 0;//zwd->inBuffer.pos;
@@ -553,10 +573,10 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
         zwd->outBuffer.size = strm->avail_out;
         zwd->outBuffer.pos = 0;
         errorCode = ZSTD_decompressStream(zwd->zbd, &zwd->outBuffer, &zwd->inBuffer);
-     //   LOG_WRAPPER("2 inpos=%d inBuffer.pos=%d inBuffer.size=%d outBuffer.pos=%d\n", (int)inPos, (int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos);
-        LOG_WRAPPER("ZSTD_decompressStream2 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)strm->avail_in, (int)strm->avail_out);
+     //   LOG_WRAPPERD("2 inpos=%d inBuffer.pos=%d inBuffer.size=%d outBuffer.pos=%d\n", (int)inPos, (int)zwd->inBuffer.pos, (int)zwd->inBuffer.size, (int)zwd->outBuffer.pos);
+        LOG_WRAPPERD("inflate ZSTD_decompressStream2 errorCode=%d srcSize=%d dstCapacity=%d\n", (int)errorCode, (int)strm->avail_in, (int)strm->avail_out);
         if (ZSTD_isError(errorCode)) {
-            LOG_WRAPPER("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
+            LOG_WRAPPERD("ERROR: ZSTD_decompressStream %s\n", ZSTD_getErrorName(errorCode));
             zwd->errorCount++;
             if (zwd->errorCount<=1) return Z_NEED_DICT; else goto error;
         }
@@ -566,11 +586,13 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
         strm->total_in += zwd->inBuffer.pos - inPos;
         strm->next_in += zwd->inBuffer.pos - inPos;
         strm->avail_in -= zwd->inBuffer.pos - inPos;
-        if (errorCode == 0) return Z_STREAM_END;
-        return Z_OK;
+        if (errorCode == 0) { LOG_WRAPPERD("inflate Z_STREAM_END1 strm->total_in=%d strm->avail_out=%d strm->total_out=%d\n", (int)strm->total_in, (int)strm->avail_out, (int)strm->total_out); return Z_STREAM_END; }
+        goto finish;
 error:
         return ZWRAPD_finish_with_error(zwd, strm, 0);
     }
+finish:
+    LOG_WRAPPERD("- inflate2 flush=%d avail_in=%d avail_out=%d total_in=%d total_out=%d\n", (int)flush, (int)strm->avail_in, (int)strm->avail_out, (int)strm->total_in, (int)strm->total_out);
     return Z_OK;
 }
 
@@ -581,7 +603,7 @@ ZEXTERN int ZEXPORT z_inflateEnd OF((z_streamp strm))
     if (!strm->reserved)
         return inflateEnd(strm);
 
-    LOG_WRAPPER("- inflateEnd total_in=%d total_out=%d\n", (int)(strm->total_in), (int)(strm->total_out));
+    LOG_WRAPPERD("- inflateEnd total_in=%d total_out=%d\n", (int)(strm->total_in), (int)(strm->total_out));
     {   ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
         size_t const errorCode = ZWRAP_freeDCtx(zwd);
         strm->state = NULL;
@@ -764,7 +786,7 @@ ZEXTERN int ZEXPORT z_compress OF((Bytef *dest,   uLongf *destLen,
 
     { size_t dstCapacity = *destLen;
       size_t const errorCode = ZSTD_compress(dest, dstCapacity, source, sourceLen, ZWRAP_DEFAULT_CLEVEL);
-      LOG_WRAPPER("z_compress sourceLen=%d dstCapacity=%d\n", (int)sourceLen, (int)dstCapacity);
+      LOG_WRAPPERD("z_compress sourceLen=%d dstCapacity=%d\n", (int)sourceLen, (int)dstCapacity);
       if (ZSTD_isError(errorCode)) return Z_STREAM_ERROR;
       *destLen = errorCode;
     }