Lines Matching refs:zwc
172 static size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc) in ZWRAP_freeCCtx() argument
174 if (zwc==NULL) return 0; /* support free on NULL */ in ZWRAP_freeCCtx()
175 ZSTD_freeCStream(zwc->zbc); in ZWRAP_freeCCtx()
176 ZWRAP_customFree(zwc, zwc->customMem); in ZWRAP_freeCCtx()
183 ZWRAP_CCtx* zwc; in ZWRAP_createCCtx() local
192 zwc = (ZWRAP_CCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_CCtx), customMem); in ZWRAP_createCCtx()
193 if (zwc == NULL) return NULL; in ZWRAP_createCCtx()
194 zwc->allocFunc = *strm; in ZWRAP_createCCtx()
195 customMem.opaque = &zwc->allocFunc; in ZWRAP_createCCtx()
196 zwc->customMem = customMem; in ZWRAP_createCCtx()
198 return zwc; in ZWRAP_createCCtx()
202 static int ZWRAP_initializeCStream(ZWRAP_CCtx* zwc, const void* dict, size_t dictSize, unsigned lon… in ZWRAP_initializeCStream() argument
204 LOG_WRAPPERC("- ZWRAP_initializeCStream=%p\n", zwc); in ZWRAP_initializeCStream()
205 if (zwc == NULL || zwc->zbc == NULL) return Z_STREAM_ERROR; in ZWRAP_initializeCStream()
207 if (!pledgedSrcSize) pledgedSrcSize = zwc->pledgedSrcSize; in ZWRAP_initializeCStream()
208 …{ ZSTD_parameters const params = ZSTD_getParams(zwc->compressionLevel, pledgedSrcSize, dictSize); in ZWRAP_initializeCStream()
212 initErr = ZSTD_initCStream_advanced(zwc->zbc, dict, dictSize, params, pledgedSrcSize); in ZWRAP_initializeCStream()
220 static int ZWRAPC_finishWithError(ZWRAP_CCtx* zwc, z_streamp strm, int error) in ZWRAPC_finishWithError() argument
223 if (zwc) ZWRAP_freeCCtx(zwc); in ZWRAPC_finishWithError()
231 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAPC_finishWithErrorMsg() local
233 if (zwc == NULL) return Z_STREAM_ERROR; in ZWRAPC_finishWithErrorMsg()
235 return ZWRAPC_finishWithError(zwc, strm, 0); in ZWRAPC_finishWithErrorMsg()
241 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAP_setPledgedSrcSize() local
242 if (zwc == NULL) return Z_STREAM_ERROR; in ZWRAP_setPledgedSrcSize()
244 zwc->pledgedSrcSize = pledgedSrcSize; in ZWRAP_setPledgedSrcSize()
245 zwc->comprState = ZWRAP_useInit; in ZWRAP_setPledgedSrcSize()
257 ZWRAP_CCtx* zwc; in z_deflateInit_() local
264 zwc = ZWRAP_createCCtx(strm); in z_deflateInit_()
265 if (zwc == NULL) return Z_MEM_ERROR; in z_deflateInit_()
270 zwc->streamEnd = 0; in z_deflateInit_()
271 zwc->totalInBytes = 0; in z_deflateInit_()
272 zwc->compressionLevel = level; in z_deflateInit_()
273 strm->state = convert_into_sis(zwc); /* use state which in not used by user */ in z_deflateInit_()
299 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAP_deflateReset_keepDict() local
300 if (zwc) { in ZWRAP_deflateReset_keepDict()
301 zwc->streamEnd = 0; in ZWRAP_deflateReset_keepDict()
302 zwc->totalInBytes = 0; in ZWRAP_deflateReset_keepDict()
321 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateReset() local
322 if (zwc) zwc->comprState = ZWRAP_useInit; in z_deflateReset()
337 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateSetDictionary() local
338 LOG_WRAPPERC("- deflateSetDictionary level=%d\n", (int)zwc->compressionLevel); in z_deflateSetDictionary()
339 if (!zwc) return Z_STREAM_ERROR; in z_deflateSetDictionary()
340 if (zwc->zbc == NULL) { in z_deflateSetDictionary()
341 zwc->zbc = ZSTD_createCStream_advanced(zwc->customMem); in z_deflateSetDictionary()
342 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflateSetDictionary()
344 { int res = ZWRAP_initializeCStream(zwc, dictionary, dictLength, ZSTD_CONTENTSIZE_UNKNOWN); in z_deflateSetDictionary()
345 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); } in z_deflateSetDictionary()
346 zwc->comprState = ZWRAP_useReset; in z_deflateSetDictionary()
355 ZWRAP_CCtx* zwc; in z_deflate() local
363 zwc = (ZWRAP_CCtx*) strm->state; in z_deflate()
364 if (zwc == NULL) { LOG_WRAPPERC("zwc == NULL\n"); return Z_STREAM_ERROR; } in z_deflate()
366 if (zwc->zbc == NULL) { in z_deflate()
367 zwc->zbc = ZSTD_createCStream_advanced(zwc->customMem); in z_deflate()
368 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
369 …{ int const initErr = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in :… in z_deflate()
370 if (initErr != Z_OK) return ZWRAPC_finishWithError(zwc, strm, initErr); } in z_deflate()
371 if (flush != Z_FINISH) zwc->comprState = ZWRAP_useReset; in z_deflate()
373 if (zwc->totalInBytes == 0) { in z_deflate()
374 if (zwc->comprState == ZWRAP_useReset) { in z_deflate()
375 …size_t const resetErr = ZSTD_resetCStream(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pl… in z_deflate()
379 return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
382 …int const res = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in : ZSTD_… in z_deflate()
383 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); in z_deflate()
384 if (flush != Z_FINISH) zwc->comprState = ZWRAP_useReset; in z_deflate()
391 zwc->inBuffer.src = strm->next_in; in z_deflate()
392 zwc->inBuffer.size = strm->avail_in; in z_deflate()
393 zwc->inBuffer.pos = 0; in z_deflate()
394 zwc->outBuffer.dst = strm->next_out; in z_deflate()
395 zwc->outBuffer.size = strm->avail_out; in z_deflate()
396 zwc->outBuffer.pos = 0; in z_deflate()
397 { size_t const cErr = ZSTD_compressStream(zwc->zbc, &zwc->outBuffer, &zwc->inBuffer); in z_deflate()
398 …eflate ZSTD_compressStream srcSize=%d dstCapacity=%d\n", (int)zwc->inBuffer.size, (int)zwc->outBuf… in z_deflate()
399 if (ZSTD_isError(cErr)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
401 strm->next_out += zwc->outBuffer.pos; in z_deflate()
402 strm->total_out += zwc->outBuffer.pos; in z_deflate()
403 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
404 strm->total_in += zwc->inBuffer.pos; in z_deflate()
405 zwc->totalInBytes += zwc->inBuffer.pos; in z_deflate()
406 strm->next_in += zwc->inBuffer.pos; in z_deflate()
407 strm->avail_in -= zwc->inBuffer.pos; in z_deflate()
419 if (zwc->streamEnd) return Z_STREAM_END; in z_deflate()
420 zwc->outBuffer.dst = strm->next_out; in z_deflate()
421 zwc->outBuffer.size = strm->avail_out; in z_deflate()
422 zwc->outBuffer.pos = 0; in z_deflate()
423 bytesLeft = ZSTD_endStream(zwc->zbc, &zwc->outBuffer); in z_deflate()
425 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
426 strm->next_out += zwc->outBuffer.pos; in z_deflate()
427 strm->total_out += zwc->outBuffer.pos; in z_deflate()
428 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
430 zwc->streamEnd = 1; in z_deflate()
438 zwc->outBuffer.dst = strm->next_out; in z_deflate()
439 zwc->outBuffer.size = strm->avail_out; in z_deflate()
440 zwc->outBuffer.pos = 0; in z_deflate()
441 bytesLeft = ZSTD_flushStream(zwc->zbc, &zwc->outBuffer); in z_deflate()
443 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
444 strm->next_out += zwc->outBuffer.pos; in z_deflate()
445 strm->total_out += zwc->outBuffer.pos; in z_deflate()
446 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
461 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateEnd() local
462 if (zwc == NULL) return Z_OK; /* structures are already freed */ in z_deflateEnd()
464 errorCode = ZWRAP_freeCCtx(zwc); in z_deflateEnd()