diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index 9e565139c..523c49bb4 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -707,7 +707,7 @@ size_t ZSTD_CDict_loadDictionary(ZSTD_CDict* cdict, const void* dict, size_t dic

Same as ZSTD_compress_generic(), but using only simple integral types as arguments. Argument list is less expressive than ZSTD_{in,out}Buffer, - but can be helpful for binders towards dynamic languages + but can be helpful for binders to dynamic languages which have troubles handling structures containing memory pointers.


diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 083f891b3..48eb24ddf 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -3734,6 +3734,16 @@ size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuf return ZSTD_compressStream_generic(zcs, output, input, ZSTD_e_continue); } +/*! ZSTDMT_initCStream_internal() : + * Private use only. Init streaming operation. + * expects params to be valid. + * must receive dict, or cdict, or none, but not both. + * @return : 0, or an error code */ +size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs, + const void* dict, size_t dictSize, const ZSTD_CDict* cdict, + ZSTD_parameters params, unsigned long long pledgedSrcSize); + + size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, @@ -3750,12 +3760,19 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, if (cctx->compressionLevel != ZSTD_CLEVEL_CUSTOM) params.cParams = ZSTD_getCParams(cctx->compressionLevel, cctx->frameContentSize, 0 /* dictSize */); - CHECK_F( ZSTD_resetCStream_internal(cctx, params, cctx->frameContentSize) ); + if (cctx->nbThreads > 1) { + CHECK_F( ZSTDMT_initCStream_internal(cctx->mtctx, NULL, 0, cctx->cdict, params, cctx->frameContentSize) ); + } else { + CHECK_F( ZSTD_resetCStream_internal(cctx, params, cctx->frameContentSize) ); + } } + + if (cctx->nbThreads > 1) { + DEBUGLOG(5, "starting ZSTDMT_compressStream_generic"); + return ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp) ; } DEBUGLOG(5, "starting ZSTD_compressStream_generic"); CHECK_F( ZSTD_compressStream_generic(cctx, output, input, endOp) ); - DEBUGLOG(5, "completing ZSTD_compress_generic"); return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */ } @@ -3773,7 +3790,6 @@ size_t ZSTD_compress_generic_simpleArgs ( *dstPos = output.pos; *srcPos = input.pos; return cErr; - } diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index c71dcd63b..09ac51218 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -559,9 +559,9 @@ static void ZSTDMT_waitForAllJobsCompleted(ZSTDMT_CCtx* zcs) } -static size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs, - const void* dict, size_t dictSize, const ZSTD_CDict* cdict, - ZSTD_parameters params, unsigned long long pledgedSrcSize) +size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs, + const void* dict, size_t dictSize, const ZSTD_CDict* cdict, + ZSTD_parameters params, unsigned long long pledgedSrcSize) { /* params are supposed to be fully validated at this point */ assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); @@ -849,3 +849,22 @@ size_t ZSTDMT_endStream(ZSTDMT_CCtx* zcs, ZSTD_outBuffer* output) return ZSTD_endStream(zcs->cctxPool->cctx[0], output); return ZSTDMT_flushStream_internal(zcs, output, 1); } + +size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, + ZSTD_outBuffer* output, + ZSTD_inBuffer* input, + ZSTD_EndDirective endOp) +{ + CHECK_F (ZSTDMT_compressStream(mtctx, output, input)); + switch(endOp) + { + case ZSTD_e_flush: + return ZSTDMT_flushStream(mtctx, output); + case ZSTD_e_end: + return ZSTDMT_endStream(mtctx, output); + case ZSTD_e_continue: + return 1; + default: + return ERROR(GENERIC); + } +} diff --git a/lib/compress/zstdmt_compress.h b/lib/compress/zstdmt_compress.h index 267ed3e2f..8b0ca824f 100644 --- a/lib/compress/zstdmt_compress.h +++ b/lib/compress/zstdmt_compress.h @@ -85,6 +85,19 @@ typedef enum { ZSTDLIB_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSDTMT_parameter parameter, unsigned value); +/*! ZSTDMT_compressStream_generic() : + * Combines ZSTDMT_compressStream() with ZSTDMT_flushStream() or ZSTDMT_endStream() + * depending on flush directive + * @return : minimum amount of data still to be flushed + * 0 if fully flushed + * or an error code */ +ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, + ZSTD_outBuffer* output, + ZSTD_inBuffer* input, + ZSTD_EndDirective endOp); + + + #if defined (__cplusplus) } #endif diff --git a/lib/zstd.h b/lib/zstd.h index b7fbbea1c..357af9194 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -828,7 +828,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx); /* Not ready yet ! */ * Same as ZSTD_compress_generic(), * but using only simple integral types as arguments. * Argument list is less expressive than ZSTD_{in,out}Buffer, - * but can be helpful for binders towards dynamic languages + * but can be helpful for binders to dynamic languages * which have troubles handling structures containing memory pointers. */ size_t ZSTD_compress_generic_simpleArgs (