fixed ZSTD_compress2()

as suggested by @terrelln
dev
Yann Collet 2018-12-10 17:33:49 -08:00
parent 0c404a48f0
commit c226a7b9f3
2 changed files with 16 additions and 12 deletions

View File

@ -4060,19 +4060,21 @@ size_t ZSTD_compress2(ZSTD_CCtx* cctx,
void* dst, size_t dstCapacity, void* dst, size_t dstCapacity,
const void* src, size_t srcSize) const void* src, size_t srcSize)
{ {
size_t oPos = 0; ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only);
size_t iPos = 0; { size_t oPos = 0;
size_t const result = ZSTD_compressStream2_simpleArgs(cctx, size_t iPos = 0;
dst, dstCapacity, &oPos, size_t const result = ZSTD_compressStream2_simpleArgs(cctx,
src, srcSize, &iPos, dst, dstCapacity, &oPos,
ZSTD_e_end); src, srcSize, &iPos,
assert(iPos == srcSize); ZSTD_e_end);
if (ZSTD_isError(result)) return result; if (ZSTD_isError(result)) return result;
if (result != 0) { /* compression not completed, due to lack of output space */ assert(iPos == srcSize);
assert(oPos == dstCapacity); if (result != 0) { /* compression not completed, due to lack of output space */
return ERROR(dstSize_tooSmall); assert(oPos == dstCapacity);
return ERROR(dstSize_tooSmall);
}
return oPos;
} }
return oPos;
} }
/*====== Finalize ======*/ /*====== Finalize ======*/

View File

@ -750,6 +750,8 @@ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
/*! ZSTD_compress2() : /*! ZSTD_compress2() :
* Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API. * Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
* ZSTD_compress2() always starts a new frame.
* Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
* - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*() * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
* - The function is always blocking, returns when compression is completed. * - The function is always blocking, returns when compression is completed.
* Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.