[lib] Set ZSTD_c_stable{In,Out}Buffer in ZSTD_compress2()
Sets these parameters in ZSTD_compress2() then resets them to their orignal values after the compression call. An alternative design could be to add a flush mode `ZSTD_e_singlePass` which implies `ZSTD_c_stable{In,Out}Buffer` but only for a single compression call, by directly setting the applied parameters. I've opted for the smaller change, but this is open for discussion.
This commit is contained in:
parent
c74be3f6de
commit
809b2f2071
@ -4364,14 +4364,22 @@ size_t ZSTD_compress2(ZSTD_CCtx* cctx,
|
||||
void* dst, size_t dstCapacity,
|
||||
const void* src, size_t srcSize)
|
||||
{
|
||||
ZSTD_bufferMode_e const originalInBufferMode = cctx->requestedParams.inBufferMode;
|
||||
ZSTD_bufferMode_e const originalOutBufferMode = cctx->requestedParams.outBufferMode;
|
||||
DEBUGLOG(4, "ZSTD_compress2 (srcSize=%u)", (unsigned)srcSize);
|
||||
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only);
|
||||
/* Enable stable input/output buffers. */
|
||||
cctx->requestedParams.inBufferMode = ZSTD_bm_stable;
|
||||
cctx->requestedParams.outBufferMode = ZSTD_bm_stable;
|
||||
{ size_t oPos = 0;
|
||||
size_t iPos = 0;
|
||||
size_t const result = ZSTD_compressStream2_simpleArgs(cctx,
|
||||
dst, dstCapacity, &oPos,
|
||||
src, srcSize, &iPos,
|
||||
ZSTD_e_end);
|
||||
/* Reset to the original values. */
|
||||
cctx->requestedParams.inBufferMode = originalInBufferMode;
|
||||
cctx->requestedParams.outBufferMode = originalOutBufferMode;
|
||||
FORWARD_IF_ERROR(result, "ZSTD_compressStream2_simpleArgs failed");
|
||||
if (result != 0) { /* compression not completed, due to lack of output space */
|
||||
assert(oPos == dstCapacity);
|
||||
|
Loading…
Reference in New Issue
Block a user