Lines Matching refs:zwc

106 static size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc)  in ZWRAP_freeCCtx()  argument
108 if (zwc==NULL) return 0; /* support free on NULL */ in ZWRAP_freeCCtx()
109 ZSTD_freeCStream(zwc->zbc); in ZWRAP_freeCCtx()
110 ZSTD_free(zwc, zwc->customMem); in ZWRAP_freeCCtx()
117 ZWRAP_CCtx* zwc; in ZWRAP_createCCtx() local
120 zwc = (ZWRAP_CCtx*)strm->zalloc(strm->opaque, 1, sizeof(ZWRAP_CCtx)); in ZWRAP_createCCtx()
121 if (zwc==NULL) return NULL; in ZWRAP_createCCtx()
122 memset(zwc, 0, sizeof(ZWRAP_CCtx)); in ZWRAP_createCCtx()
123 memcpy(&zwc->allocFunc, strm, sizeof(z_stream)); in ZWRAP_createCCtx()
124 …{ ZSTD_customMem const ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, &zwc->allocFun… in ZWRAP_createCCtx()
125 zwc->customMem = ZWRAP_customMem; } in ZWRAP_createCCtx()
127 zwc = (ZWRAP_CCtx*)calloc(1, sizeof(*zwc)); in ZWRAP_createCCtx()
128 if (zwc==NULL) return NULL; in ZWRAP_createCCtx()
131 return zwc; in ZWRAP_createCCtx()
135 static int ZWRAP_initializeCStream(ZWRAP_CCtx* zwc, const void* dict, size_t dictSize, unsigned lon… in ZWRAP_initializeCStream() argument
137 LOG_WRAPPERC("- ZWRAP_initializeCStream=%p\n", zwc); in ZWRAP_initializeCStream()
138 if (zwc == NULL || zwc->zbc == NULL) return Z_STREAM_ERROR; in ZWRAP_initializeCStream()
140 if (!pledgedSrcSize) pledgedSrcSize = zwc->pledgedSrcSize; in ZWRAP_initializeCStream()
141 …{ ZSTD_parameters const params = ZSTD_getParams(zwc->compressionLevel, pledgedSrcSize, dictSize); in ZWRAP_initializeCStream()
145 initErr = ZSTD_initCStream_advanced(zwc->zbc, dict, dictSize, params, pledgedSrcSize); in ZWRAP_initializeCStream()
153 static int ZWRAPC_finishWithError(ZWRAP_CCtx* zwc, z_streamp strm, int error) in ZWRAPC_finishWithError() argument
156 if (zwc) ZWRAP_freeCCtx(zwc); in ZWRAPC_finishWithError()
164 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAPC_finishWithErrorMsg() local
166 if (zwc == NULL) return Z_STREAM_ERROR; in ZWRAPC_finishWithErrorMsg()
168 return ZWRAPC_finishWithError(zwc, strm, 0); in ZWRAPC_finishWithErrorMsg()
174 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAP_setPledgedSrcSize() local
175 if (zwc == NULL) return Z_STREAM_ERROR; in ZWRAP_setPledgedSrcSize()
177 zwc->pledgedSrcSize = pledgedSrcSize; in ZWRAP_setPledgedSrcSize()
178 zwc->comprState = ZWRAP_useInit; in ZWRAP_setPledgedSrcSize()
186 ZWRAP_CCtx* zwc; in z_deflateInit_() local
193 zwc = ZWRAP_createCCtx(strm); in z_deflateInit_()
194 if (zwc == NULL) return Z_MEM_ERROR; in z_deflateInit_()
199 zwc->streamEnd = 0; in z_deflateInit_()
200 zwc->totalInBytes = 0; in z_deflateInit_()
201 zwc->compressionLevel = level; in z_deflateInit_()
202 strm->state = (struct internal_state*) zwc; /* use state which in not used by user */ in z_deflateInit_()
228 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in ZWRAP_deflateReset_keepDict() local
229 if (zwc) { in ZWRAP_deflateReset_keepDict()
230 zwc->streamEnd = 0; in ZWRAP_deflateReset_keepDict()
231 zwc->totalInBytes = 0; in ZWRAP_deflateReset_keepDict()
250 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateReset() local
251 if (zwc) zwc->comprState = ZWRAP_useInit; in z_deflateReset()
266 { ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateSetDictionary() local
267 LOG_WRAPPERC("- deflateSetDictionary level=%d\n", (int)zwc->compressionLevel); in z_deflateSetDictionary()
268 if (!zwc) return Z_STREAM_ERROR; in z_deflateSetDictionary()
269 if (zwc->zbc == NULL) { in z_deflateSetDictionary()
270 zwc->zbc = ZSTD_createCStream_advanced(zwc->customMem); in z_deflateSetDictionary()
271 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflateSetDictionary()
273 { int res = ZWRAP_initializeCStream(zwc, dictionary, dictLength, ZSTD_CONTENTSIZE_UNKNOWN); in z_deflateSetDictionary()
274 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); } in z_deflateSetDictionary()
275 zwc->comprState = ZWRAP_useReset; in z_deflateSetDictionary()
284 ZWRAP_CCtx* zwc; in z_deflate() local
292 zwc = (ZWRAP_CCtx*) strm->state; in z_deflate()
293 if (zwc == NULL) { LOG_WRAPPERC("zwc == NULL\n"); return Z_STREAM_ERROR; } in z_deflate()
295 if (zwc->zbc == NULL) { in z_deflate()
296 zwc->zbc = ZSTD_createCStream_advanced(zwc->customMem); in z_deflate()
297 if (zwc->zbc == NULL) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
298 …{ int const initErr = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in :… in z_deflate()
299 if (initErr != Z_OK) return ZWRAPC_finishWithError(zwc, strm, initErr); } in z_deflate()
300 if (flush != Z_FINISH) zwc->comprState = ZWRAP_useReset; in z_deflate()
302 if (zwc->totalInBytes == 0) { in z_deflate()
303 if (zwc->comprState == ZWRAP_useReset) { in z_deflate()
304 …size_t const resetErr = ZSTD_resetCStream(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pl… in z_deflate()
308 return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
311 …int const res = ZWRAP_initializeCStream(zwc, NULL, 0, (flush == Z_FINISH) ? strm->avail_in : ZSTD_… in z_deflate()
312 if (res != Z_OK) return ZWRAPC_finishWithError(zwc, strm, res); in z_deflate()
313 if (flush != Z_FINISH) zwc->comprState = ZWRAP_useReset; in z_deflate()
320 zwc->inBuffer.src = strm->next_in; in z_deflate()
321 zwc->inBuffer.size = strm->avail_in; in z_deflate()
322 zwc->inBuffer.pos = 0; in z_deflate()
323 zwc->outBuffer.dst = strm->next_out; in z_deflate()
324 zwc->outBuffer.size = strm->avail_out; in z_deflate()
325 zwc->outBuffer.pos = 0; in z_deflate()
326 { size_t const cErr = ZSTD_compressStream(zwc->zbc, &zwc->outBuffer, &zwc->inBuffer); in z_deflate()
327 …eflate ZSTD_compressStream srcSize=%d dstCapacity=%d\n", (int)zwc->inBuffer.size, (int)zwc->outBuf… in z_deflate()
328 if (ZSTD_isError(cErr)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
330 strm->next_out += zwc->outBuffer.pos; in z_deflate()
331 strm->total_out += zwc->outBuffer.pos; in z_deflate()
332 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
333 strm->total_in += zwc->inBuffer.pos; in z_deflate()
334 zwc->totalInBytes += zwc->inBuffer.pos; in z_deflate()
335 strm->next_in += zwc->inBuffer.pos; in z_deflate()
336 strm->avail_in -= zwc->inBuffer.pos; in z_deflate()
348 if (zwc->streamEnd) return Z_STREAM_END; in z_deflate()
349 zwc->outBuffer.dst = strm->next_out; in z_deflate()
350 zwc->outBuffer.size = strm->avail_out; in z_deflate()
351 zwc->outBuffer.pos = 0; in z_deflate()
352 bytesLeft = ZSTD_endStream(zwc->zbc, &zwc->outBuffer); in z_deflate()
354 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
355 strm->next_out += zwc->outBuffer.pos; in z_deflate()
356 strm->total_out += zwc->outBuffer.pos; in z_deflate()
357 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
359 zwc->streamEnd = 1; in z_deflate()
367 zwc->outBuffer.dst = strm->next_out; in z_deflate()
368 zwc->outBuffer.size = strm->avail_out; in z_deflate()
369 zwc->outBuffer.pos = 0; in z_deflate()
370 bytesLeft = ZSTD_flushStream(zwc->zbc, &zwc->outBuffer); in z_deflate()
372 if (ZSTD_isError(bytesLeft)) return ZWRAPC_finishWithError(zwc, strm, 0); in z_deflate()
373 strm->next_out += zwc->outBuffer.pos; in z_deflate()
374 strm->total_out += zwc->outBuffer.pos; in z_deflate()
375 strm->avail_out -= zwc->outBuffer.pos; in z_deflate()
390 ZWRAP_CCtx* zwc = (ZWRAP_CCtx*) strm->state; in z_deflateEnd() local
391 if (zwc == NULL) return Z_OK; /* structures are already freed */ in z_deflateEnd()
393 errorCode = ZWRAP_freeCCtx(zwc); in z_deflateEnd()