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()
209 … ZSTD_parameters const params = ZSTD_getParams(zwc->compressionLevel, pledgedSrcSize, dictSize); in ZWRAP_initializeCStream()
215 initErr |= ZSTD_isError(ZSTD_CCtx_reset(zwc->zbc, ZSTD_reset_session_only)); in ZWRAP_initializeCStream()
217 initErr |= ZSTD_isError(ZSTD_CCtx_setParametersUsingCCtxParams(zwc->zbc, cctxParams)); in ZWRAP_initializeCStream()
218 initErr |= ZSTD_isError(ZSTD_CCtx_setPledgedSrcSize(zwc->zbc, pledgedSrcSize)); in ZWRAP_initializeCStream()
219 initErr |= ZSTD_isError(ZSTD_CCtx_loadDictionary(zwc->zbc, dict, dictSize)); in ZWRAP_initializeCStream()
229 static int ZWRAPC_finishWithError(ZWRAP_CCtx* zwc, z_streamp strm, int error) in ZWRAPC_finishWithError() argument
232 if (zwc) ZWRAP_freeCCtx(zwc); in ZWRAPC_finishWithError()
240 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAPC_finishWithErrorMsg() local
242 if (zwc == NULL) return Z_STREAM_ERROR; in ZWRAPC_finishWithErrorMsg()
244 return ZWRAPC_finishWithError(zwc, strm, 0); in ZWRAPC_finishWithErrorMsg()
250 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAP_setPledgedSrcSize() local
251 if (zwc == NULL) return Z_STREAM_ERROR; in ZWRAP_setPledgedSrcSize()
253 zwc->pledgedSrcSize = pledgedSrcSize; in ZWRAP_setPledgedSrcSize()
254 zwc->comprState = ZWRAP_useInit; in ZWRAP_setPledgedSrcSize()
266 ZWRAP_CCtx* zwc; in z_deflateInit_() local
273 zwc = ZWRAP_createCCtx(strm); in z_deflateInit_()
274 if (zwc == NULL) return Z_MEM_ERROR; in z_deflateInit_()
279 zwc->streamEnd = 0; in z_deflateInit_()
280 zwc->totalInBytes = 0; in z_deflateInit_()
281 zwc->compressionLevel = level; in z_deflateInit_()
282 strm->state = convert_into_sis(zwc); /* use state which in not used by user */ in z_deflateInit_()
308 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAP_deflateReset_keepDict() local
309 if (zwc) { in ZWRAP_deflateReset_keepDict()
310 zwc->streamEnd = 0; in ZWRAP_deflateReset_keepDict()
311 zwc->totalInBytes = 0; in ZWRAP_deflateReset_keepDict()
330 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateReset() local
331 if (zwc) zwc->comprState = ZWRAP_useInit; in z_deflateReset()
346 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateSetDictionary() local
347 LOG_WRAPPERC("- deflateSetDictionary level=%d\n", (int)zwc->compressionLevel); in z_deflateSetDictionary()
348 if (!zwc) return Z_STREAM_ERROR; in z_deflateSetDictionary()
349 if (zwc->zbc == NULL) { in z_deflateSetDictionary()
350 zwc->zbc = ZSTD_createCStream_advanced(zwc->customMem); in z_deflateSetDictionary()
351 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflateSetDictionary()
353 { int res = ZWRAP_initializeCStream(zwc, dictionary, dictLength, ZSTD_CONTENTSIZE_UNKNOWN); in z_deflateSetDictionary()
354 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); } in z_deflateSetDictionary()
355 zwc->comprState = ZWRAP_useReset; in z_deflateSetDictionary()
364 ZWRAP_CCtx* zwc; in z_deflate() local
372 zwc = (ZWRAP_CCtx*) strm->state; in z_deflate()
373 if (zwc == NULL) { LOG_WRAPPERC("zwc == NULL\n"); return Z_STREAM_ERROR; } in z_deflate()
375 if (zwc->zbc == NULL) { in z_deflate()
376 zwc->zbc = ZSTD_createCStream_advanced(zwc->customMem); in z_deflate()
377 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
378 …{ int const initErr = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in :… in z_deflate()
379 if (initErr != Z_OK) return ZWRAPC_finishWithError(zwc, strm, initErr); } in z_deflate()
380 if (flush != Z_FINISH) zwc->comprState = ZWRAP_useReset; in z_deflate()
382 if (zwc->totalInBytes == 0) { in z_deflate()
383 if (zwc->comprState == ZWRAP_useReset) { in z_deflate()
384 size_t resetErr = ZSTD_CCtx_reset(zwc->zbc, ZSTD_reset_session_only); in z_deflate()
388 return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
390 …resetErr = ZSTD_CCtx_setPledgedSrcSize(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pledg… in z_deflate()
394 return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
397 …int const res = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in : ZSTD_… in z_deflate()
398 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); in z_deflate()
399 if (flush != Z_FINISH) zwc->comprState = ZWRAP_useReset; in z_deflate()
406 zwc->inBuffer.src = strm->next_in; in z_deflate()
407 zwc->inBuffer.size = strm->avail_in; in z_deflate()
408 zwc->inBuffer.pos = 0; in z_deflate()
409 zwc->outBuffer.dst = strm->next_out; in z_deflate()
410 zwc->outBuffer.size = strm->avail_out; in z_deflate()
411 zwc->outBuffer.pos = 0; in z_deflate()
412 { size_t const cErr = ZSTD_compressStream(zwc->zbc, &zwc->outBuffer, &zwc->inBuffer); in z_deflate()
413 …eflate ZSTD_compressStream srcSize=%d dstCapacity=%d\n", (int)zwc->inBuffer.size, (int)zwc->outBuf… in z_deflate()
414 if (ZSTD_isError(cErr)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
416 strm->next_out += zwc->outBuffer.pos; in z_deflate()
417 strm->total_out += zwc->outBuffer.pos; in z_deflate()
418 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
419 strm->total_in += zwc->inBuffer.pos; in z_deflate()
420 zwc->totalInBytes += zwc->inBuffer.pos; in z_deflate()
421 strm->next_in += zwc->inBuffer.pos; in z_deflate()
422 strm->avail_in -= zwc->inBuffer.pos; in z_deflate()
434 if (zwc->streamEnd) return Z_STREAM_END; in z_deflate()
435 zwc->outBuffer.dst = strm->next_out; in z_deflate()
436 zwc->outBuffer.size = strm->avail_out; in z_deflate()
437 zwc->outBuffer.pos = 0; in z_deflate()
438 bytesLeft = ZSTD_endStream(zwc->zbc, &zwc->outBuffer); in z_deflate()
440 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
441 strm->next_out += zwc->outBuffer.pos; in z_deflate()
442 strm->total_out += zwc->outBuffer.pos; in z_deflate()
443 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
445 zwc->streamEnd = 1; in z_deflate()
453 zwc->outBuffer.dst = strm->next_out; in z_deflate()
454 zwc->outBuffer.size = strm->avail_out; in z_deflate()
455 zwc->outBuffer.pos = 0; in z_deflate()
456 bytesLeft = ZSTD_flushStream(zwc->zbc, &zwc->outBuffer); in z_deflate()
458 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
459 strm->next_out += zwc->outBuffer.pos; in z_deflate()
460 strm->total_out += zwc->outBuffer.pos; in z_deflate()
461 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
476 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateEnd() local
477 if (zwc == NULL) return Z_OK; /* structures are already freed */ in z_deflateEnd()
479 errorCode = ZWRAP_freeCCtx(zwc); in z_deflateEnd()