]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add initialization/allocation functions for opaque params
authorStella Lau <laus@fb.com>
Fri, 18 Aug 2017 01:45:04 +0000 (18:45 -0700)
committerStella Lau <laus@fb.com>
Fri, 18 Aug 2017 01:45:04 +0000 (18:45 -0700)
lib/compress/zstd_compress.c
lib/zstd.h

index b5bdf680eaacb8e0fb772ca234a54f3e8f9d6340..509f8bedcd23a931d9e9ec5879a057904a209667 100644 (file)
@@ -230,6 +230,44 @@ static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
     return cctxParams;
 }
 
+ZSTD_CCtx_params* ZSTD_createCCtxParams(void)
+{
+    ZSTD_CCtx_params* params =
+        (ZSTD_CCtx_params*)ZSTD_calloc(sizeof(ZSTD_CCtx_params),
+                                       ZSTD_defaultCMem);
+    if (!params) { return NULL; }
+    // TODO
+//    params->compressionLevel = ZSTD_CLEVEL_DEFAULT;
+    return params;
+}
+
+size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* params,
+                         ZSTD_compressionParameters cParams)
+{
+    CHECK_F( params == NULL );
+    memset(params, 0, sizeof(ZSTD_CCtx_params));
+    params->cParams = cParams;
+    return 0;
+}
+
+ZSTD_CCtx_params* ZSTD_createAndInitCCtxParams(
+        int compressionLevel, unsigned long long estimatedSrcSize,
+        size_t dictSize)
+{
+    ZSTD_CCtx_params* params = ZSTD_createCCtxParams();
+    if (params == NULL) { return NULL; }
+    ZSTD_initCCtxParams(params, ZSTD_getCParams(
+                            compressionLevel, estimatedSrcSize, dictSize));
+    return params;
+}
+
+size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params)
+{
+    ZSTD_free(params, ZSTD_defaultCMem);
+    return 0;
+}
+
+
 
 static ZSTD_parameters ZSTD_getParamsFromCCtx(const ZSTD_CCtx* cctx) {
     return ZSTD_getParamsFromCCtxParams(cctx->appliedParams);
index 2111c9de01b36ba45988f876d143ffcb03573d98..b847d01f21b3d19fbc48ea67fb23d7d4e20d6495 100644 (file)
@@ -611,6 +611,12 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_initStaticCDict_advanced_opaque(
                             unsigned byReference, ZSTD_dictMode_e dictMode,
                             ZSTD_CCtx_params* params);
 
+ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
+ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createAndInitCCtxParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
+ZSTDLIB_API size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* params, ZSTD_compressionParameters cParams);
+ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
+
+
 /*! ZSTD_getCParams() :
 *   @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
 *   `estimatedSrcSize` value is optional, select 0 if not known */