From eac309c71b8f5784bb7f535be8c377964f00362b Mon Sep 17 00:00:00 2001 From: Luke Pitt Date: Wed, 4 Nov 2020 11:37:37 +0000 Subject: [PATCH] Add ZSTD_getDictID_fromCDict function to experimental section --- doc/zstd_manual.html | 6 ++++++ lib/compress/zstd_compress.c | 11 +++++++++++ lib/zstd.h | 6 ++++++ tests/fuzzer.c | 1 + 4 files changed, 24 insertions(+) diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index fe58f78c..77d4b8e6 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -1158,6 +1158,12 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< t note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef


+
unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
+

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. +


+
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
 

@return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. `estimatedSrcSize` value is optional, select 0 if not known diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 97219dee..74f2cee3 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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( diff --git a/lib/zstd.h b/lib/zstd.h index c1fb55cf..18720cc7 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -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 */ diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 755c13bd..796e8bed 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -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);