]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
ZSTD_decompress_usingDDict() compatible with Legacy mode
authorYann Collet <yann.collet.73@gmail.com>
Wed, 6 Jul 2016 18:30:52 +0000 (20:30 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Wed, 6 Jul 2016 18:32:27 +0000 (20:32 +0200)
NEWS
lib/common/zstd.h
lib/decompress/zstd_decompress.c

diff --git a/NEWS b/NEWS
index 4569e12fcc10a93d2c1af002617975bb8e17bf8b..3793ed44b381be83f7b37b37edd04ac0ceeebf23 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ v0.7.3
 added : `--` separator, stating that all following arguments are file names. Suggested by Chip Turner.
 added : OpenBSD target, by Juan Francisco Cantero Hurtado
 fixed : dictBuilder using HC levels, reported by Bartosz Taudul
+fixed : legacy support from ZSTD_decompress_usingDDict(), reported by Felix Handte
 
 v0.7.2
 fixed : ZSTD_decompressBlock() using multiple consecutive blocks. Reported by Greg Slazinski.
index 3dcd533db8e1083cca10ab3227a74e7e0d01bdf2..1906c1859748bc50d0c0f96a5deb0a87369efd2b 100644 (file)
@@ -408,12 +408,14 @@ ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t ds
 *  Block functions
 ****************************************/
 /*! Block functions produce and decode raw zstd blocks, without frame metadata.
+    Frame metadata cost is typically ~18 bytes, which is non-negligible on very small blocks.
     User will have to take in charge required information to regenerate data, such as compressed and content sizes.
 
     A few rules to respect :
     - Uncompressed block size must be <= ZSTD_BLOCKSIZE_MAX (128 KB)
-      + If you need to compress more, it's recommended to use ZSTD_compress() instead, since frame metadata costs become negligible.
-    - Compressing or decompressing requires a context structure
+      + If you need to compress more, cut data into multiple blocks
+      + Consider using the regular ZSTD_compress() instead, as frame metadata costs become negligible when source size is large.
+    - Compressing and decompressing require a context structure
       + Use ZSTD_createCCtx() and ZSTD_createDCtx()
     - It is necessary to init context before starting
       + compression : ZSTD_compressBegin()
@@ -423,12 +425,16 @@ ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t ds
     - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
       In which case, nothing is produced into `dst`.
       + User must test for such outcome and deal directly with uncompressed data
-      + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!
+      + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
+      + In case of multiple successive blocks, decoder must be informed of uncompressed block existence to follow proper history.
+        Use ZSTD_insertBlock() in such a case.
+        Insert block once it's copied into its final position.
 */
 
 #define ZSTD_BLOCKSIZE_MAX (128 * 1024)   /* define, for static allocation */
 ZSTDLIB_API size_t ZSTD_compressBlock  (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
 ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
+ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize);  /**< insert block into `dctx` history. Useful to track uncompressed blocks */
 
 
 /*-*************************************
index 02498aea03d4e418619d2f597a8ed7c7633578ac..3cc38cd067329415ab654d00edcce663b7448e92 100644 (file)
@@ -919,6 +919,16 @@ size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx,
 }
 
 
+/** ZSTD_insertBlock() :
+    insert `src` block into `dctx` history. Useful to track uncompressed blocks. */
+ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize)
+{
+    ZSTD_checkContinuity(dctx, blockStart);
+    dctx->previousDstEnd = (const char*)blockStart + blockSize;
+    return blockSize;
+}
+
+
 size_t ZSTD_generateNxByte(void* dst, size_t dstCapacity, BYTE byte, size_t length)
 {
     if (length > dstCapacity) return ERROR(dstSize_tooSmall);
@@ -1324,6 +1334,12 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
                                      const void* src, size_t srcSize,
                                      const ZSTD_DDict* ddict)
 {
+#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
+    {   U32 const magicNumber = MEM_readLE32(src);
+        if (ZSTD_isLegacy(magicNumber))
+            return ZSTD_decompressLegacy(dst, dstCapacity, src, srcSize, ddict->dictContent, ddict->dictContentSize, magicNumber);
+    }
+#endif
     return ZSTD_decompress_usingPreparedDCtx(dctx, ddict->refContext,
                                            dst, dstCapacity,
                                            src, srcSize);