]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add ZSTD_getDictID_fromCDict function to experimental section 2385/head
authorLuke Pitt <LukeAPitt@googlemail.com>
Wed, 4 Nov 2020 11:37:37 +0000 (11:37 +0000)
committerLuke Pitt <LukeAPitt@googlemail.com>
Wed, 4 Nov 2020 11:37:37 +0000 (11:37 +0000)
doc/zstd_manual.html
lib/compress/zstd_compress.c
lib/zstd.h
tests/fuzzer.c

index fe58f78cb1536cc0eb2de731e126e8dac2cb2648..77d4b8e633658f04ed54ffcb892c849d5382c447 100644 (file)
@@ -1158,6 +1158,12 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  </b>/**< t
   note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef 
 </p></pre><BR>
 
+<pre><b>unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
+</b><p>  Provides the dictID of the dictionary loaded into `cdict`.
+  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
+  Non-conformant dictionaries can still be loaded, but as content-only dictionaries. 
+</p></pre><BR>
+
 <pre><b>ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
 </b><p> @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
  `estimatedSrcSize` value is optional, select 0 if not known 
index 97219dee0ebda9501cda895139f13f3f7e7bdb91..74f2cee3991ca75698e7166f4b5f9c8884b36a64 100644 (file)
@@ -3798,6 +3798,17 @@ ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict* cdict)
     return cdict->matchState.cParams;
 }
 
+/*! ZSTD_getDictID_fromCDict() :
+ *  Provides the dictID of the dictionary loaded into `cdict`.
+ *  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
+ *  Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
+unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict)
+{
+    if (cdict==NULL) return 0;
+    return cdict->dictID;
+}
+
+
 /* ZSTD_compressBegin_usingCDict_advanced() :
  * cdict must be != NULL */
 size_t ZSTD_compressBegin_usingCDict_advanced(
index c1fb55cf5e201a0d0afd6193b6bf6e9de769a655..18720cc7782808cbd8cfeee31b737f21774f8d59 100644 (file)
@@ -1477,6 +1477,12 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictS
  *  note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef */
 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
 
+/*! ZSTD_getDictID_fromCDict() :
+ *  Provides the dictID of the dictionary loaded into `cdict`.
+ *  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
+ *  Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
+ZSTDLIB_API unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
+
 /*! ZSTD_getCParams() :
  * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
  * `estimatedSrcSize` value is optional, select 0 if not known */
index 755c13bdad6aa21995aac2dc505d9011572b5798..796e8beddb949d5c8aafabf7228ac0969ff1a4c4 100644 (file)
@@ -1911,6 +1911,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
                                             cParams, ZSTD_defaultCMem);
             assert(cdict != NULL);
             DISPLAYLEVEL(3, "(size : %u) : ", (unsigned)ZSTD_sizeof_CDict(cdict));
+            assert(ZSTD_getDictID_fromDict(dictBuffer, dictSize) == ZSTD_getDictID_fromCDict(cdict));
             cSize = ZSTD_compress_usingCDict(cctx, compressedBuffer, compressedBufferSize,
                                                  CNBuffer, CNBuffSize, cdict);
             ZSTD_freeCDict(cdict);