mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 11:22:38 -04:00
Use compressBound function to reserve the right amount of space.
compressBound function give the upper bound of space needed to reserve to the compression buffer. Use it instead of using a define.
This commit is contained in:
parent
e27ce444c6
commit
063e9ba80d
@ -164,8 +164,9 @@ bool compress_content(string &content,
|
|||||||
/* Compress the content if necessary */
|
/* Compress the content if necessary */
|
||||||
if (deflated) {
|
if (deflated) {
|
||||||
pthread_mutex_lock(&compressorLock);
|
pthread_mutex_lock(&compressorLock);
|
||||||
compr_buffer.reserve(COMPRESSOR_BUFFER_SIZE);
|
uLong bufferBound = compressBound(contentLength);
|
||||||
uLongf comprLen = COMPRESSOR_BUFFER_SIZE;
|
compr_buffer.reserve(bufferBound);
|
||||||
|
uLongf comprLen = compr_buffer.capacity();
|
||||||
int err = compress(&compr_buffer[0], &comprLen, (const Bytef*)(content.data()), contentLength);
|
int err = compress(&compr_buffer[0], &comprLen, (const Bytef*)(content.data()), contentLength);
|
||||||
|
|
||||||
if (err == Z_OK && comprLen > 2 && comprLen < (contentLength+2)) {
|
if (err == Z_OK && comprLen > 2 && comprLen < (contentLength+2)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user