fixed ZSTD_compress2()
as suggested by @terrelln
This commit is contained in:
parent
0c404a48f0
commit
c226a7b9f3
@ -4060,20 +4060,22 @@ 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 oPos = 0;
|
||||||
size_t iPos = 0;
|
size_t iPos = 0;
|
||||||
size_t const result = ZSTD_compressStream2_simpleArgs(cctx,
|
size_t const result = ZSTD_compressStream2_simpleArgs(cctx,
|
||||||
dst, dstCapacity, &oPos,
|
dst, dstCapacity, &oPos,
|
||||||
src, srcSize, &iPos,
|
src, srcSize, &iPos,
|
||||||
ZSTD_e_end);
|
ZSTD_e_end);
|
||||||
assert(iPos == srcSize);
|
|
||||||
if (ZSTD_isError(result)) return result;
|
if (ZSTD_isError(result)) return result;
|
||||||
|
assert(iPos == srcSize);
|
||||||
if (result != 0) { /* compression not completed, due to lack of output space */
|
if (result != 0) { /* compression not completed, due to lack of output space */
|
||||||
assert(oPos == dstCapacity);
|
assert(oPos == dstCapacity);
|
||||||
return ERROR(dstSize_tooSmall);
|
return ERROR(dstSize_tooSmall);
|
||||||
}
|
}
|
||||||
return oPos;
|
return oPos;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*====== Finalize ======*/
|
/*====== Finalize ======*/
|
||||||
|
|
||||||
|
@ -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)`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user