]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
API : changed : streaming decompression : implicit reset on starting new frames
authorYann Collet <cyan@fb.com>
Sat, 3 Dec 2016 02:37:38 +0000 (18:37 -0800)
committerYann Collet <cyan@fb.com>
Sat, 3 Dec 2016 02:37:38 +0000 (18:37 -0800)
NEWS
lib/decompress/zstd_decompress.c
lib/zstd.h
tests/zstreamtest.c

diff --git a/NEWS b/NEWS
index 69b24e635afb1c9c2d4397373a325e5e1cdb9f4e..5808895424a5f75ebeea626fe819507093f26095 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,10 +2,11 @@ v1.1.2
 Improved : faster decompression speed at ultra compression settings and in 32-bits mode
 cli : new : gzstd, experimental version able to decode .gz files, by Przemyslaw Skibinski
 cli : new : preserve file attributes
-cli : new : added zstdless
+cli : new : added zstdless and zstdgrep tools
 cli : fixed : status displays total amount decoded, even for file consisting of multiple frames (like pzstd)
 cli : fixed : zstdcat
 API : changed : zbuff prototypes now generate deprecation warnings
+API : changed : streaming decompression implicit reset on starting new frame
 Changed : reduced stack memory use
 
 v1.1.1
index 3106fa0140c411c7451b1a3957c4c7dcd6476707..7c4f54bd31ca75bf52824a00ff4c9b77f70f7258 100644 (file)
@@ -1959,7 +1959,8 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
         switch(zds->stage)
         {
         case zdss_init :
-            return ERROR(init_missing);
+            ZSTD_resetDStream(zds);   /* transparent reset on starting decoding a new frame */
+            /* fall-through */
 
         case zdss_loadHeader :
             {   size_t const hSize = ZSTD_getFrameParams(&zds->fParams, zds->headerBuffer, zds->lhSize);
index 607612026937f60d528c9417d36b2ed6d19a8d36..b7a8bb989df4fd9891e67d5ff470ed23e82e780b 100644 (file)
@@ -299,8 +299,8 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void);   /**< recommended size for output
 *  If `output.pos < output.size`, decoder has flushed everything it could.
 *  @return : 0 when a frame is completely decoded and fully flushed,
 *            an error code, which can be tested using ZSTD_isError(),
-*            any other value > 0, which means there is still some work to do to complete the frame.
-*            The return value is a suggested next input size (just an hint, to help latency).
+*            any other value > 0, which means there is still some decoding to do to complete current frame.
+*            The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame.
 * *******************************************************************************/
 
 /*=====   Streaming decompression functions   =====*/
index aa119e636a1df636bc986e3a4f2ba684a9b342e5..c21b9de9b6fc9224aac0e13be0c6722ba7215615 100644 (file)
@@ -130,7 +130,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
     U32 testNb=0;
     ZSTD_CStream* zc = ZSTD_createCStream_advanced(customMem);
     ZSTD_DStream* zd = ZSTD_createDStream_advanced(customMem);
-    ZSTD_inBuffer  inBuff;
+    ZSTD_inBuffer  inBuff, inBuff2;
     ZSTD_outBuffer outBuff;
 
     /* Create compressible test buffer */
@@ -183,12 +183,22 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
     DISPLAYLEVEL(4, "OK \n");
 
     /* Basic decompression test */
+    inBuff2 = inBuff;
     DISPLAYLEVEL(4, "test%3i : decompress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
     ZSTD_initDStream_usingDict(zd, CNBuffer, 128 KB);
     { size_t const r = ZSTD_setDStreamParameter(zd, ZSTDdsp_maxWindowSize, 1000000000);  /* large limit */
       if (ZSTD_isError(r)) goto _output_error; }
-    { size_t const r = ZSTD_decompressStream(zd, &outBuff, &inBuff);
-      if (r != 0) goto _output_error; }  /* should reach end of frame == 0; otherwise, some data left, or an error */
+    { size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inBuff);
+      if (remaining != 0) goto _output_error; }  /* should reach end of frame == 0; otherwise, some data left, or an error */
+    if (outBuff.pos != CNBufferSize) goto _output_error;   /* should regenerate the same amount */
+    if (inBuff.pos != inBuff.size) goto _output_error;   /* should have read the entire frame */
+    DISPLAYLEVEL(4, "OK \n");
+
+    /* Re-use without init */
+    DISPLAYLEVEL(4, "test%3i : decompress again without init (re-use previous settings): ", testNb++);
+    outBuff.pos = 0;
+    { size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inBuff2);
+      if (remaining != 0) goto _output_error; }  /* should reach end of frame == 0; otherwise, some data left, or an error */
     if (outBuff.pos != CNBufferSize) goto _output_error;   /* should regenerate the same amount */
     if (inBuff.pos != inBuff.size) goto _output_error;   /* should have read the entire frame */
     DISPLAYLEVEL(4, "OK \n");
@@ -553,8 +563,9 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres
         /* multi - fragments decompression test */
         if (!dictSize /* don't reset if dictionary : could be different */ && (FUZ_rand(&lseed) & 1)) {
             CHECK (ZSTD_isError(ZSTD_resetDStream(zd)), "ZSTD_resetDStream failed");
-        } else
+        } else {
             ZSTD_initDStream_usingDict(zd, dict, dictSize);
+        }
         {   size_t decompressionResult = 1;
             ZSTD_inBuffer  inBuff = { cBuffer, cSize, 0 };
             ZSTD_outBuffer outBuff= { dstBuffer, dstBufferSize, 0 };