Lines Matching refs:ctx
67 struct deflate *ctx; in zip_source_deflate() local
75 if ((ctx=(struct deflate *)malloc(sizeof(*ctx))) == NULL) { in zip_source_deflate()
80 ctx->e[0] = ctx->e[1] = 0; in zip_source_deflate()
81 ctx->eof = 0; in zip_source_deflate()
84 ctx->mem_level = TORRENT_MEM_LEVEL; in zip_source_deflate()
86 ctx->mem_level = MAX_MEM_LEVEL; in zip_source_deflate()
92 ctx)) == NULL) { in zip_source_deflate()
93 deflate_free(ctx); in zip_source_deflate()
103 compress_read(struct zip_source *src, struct deflate *ctx, in compress_read() argument
109 if (ctx->e[0] != 0) in compress_read()
115 ctx->zstr.next_out = (Bytef *)data; in compress_read()
116 ctx->zstr.avail_out = len; in compress_read()
120 ret = deflate(&ctx->zstr, ctx->eof ? Z_FINISH : 0); in compress_read()
127 if (ctx->zstr.avail_out == 0 in compress_read()
128 || (ctx->eof && ctx->zstr.avail_in == 0)) in compress_read()
133 if (ctx->zstr.avail_in == 0) { in compress_read()
134 if (ctx->eof) { in compress_read()
139 if ((n=zip_source_read(src, ctx->buffer, in compress_read()
140 sizeof(ctx->buffer))) < 0) { in compress_read()
141 zip_source_error(src, ctx->e, ctx->e+1); in compress_read()
146 ctx->eof = 1; in compress_read()
147 ctx->size = ctx->zstr.total_in; in compress_read()
151 ctx->zstr.next_in = (Bytef *)ctx->buffer; in compress_read()
152 ctx->zstr.avail_in = n; in compress_read()
161 ctx->e[0] = ZIP_ER_ZLIB; in compress_read()
162 ctx->e[1] = ret; in compress_read()
169 if (ctx->zstr.avail_out < len) in compress_read()
170 return len - ctx->zstr.avail_out; in compress_read()
172 return (ctx->e[0] == 0) ? 0 : -1; in compress_read()
178 decompress_read(struct zip_source *src, struct deflate *ctx, in decompress_read() argument
184 if (ctx->e[0] != 0) in decompress_read()
190 ctx->zstr.next_out = (Bytef *)data; in decompress_read()
191 ctx->zstr.avail_out = len; in decompress_read()
194 while (!end && ctx->zstr.avail_out) { in decompress_read()
195 ret = inflate(&ctx->zstr, Z_SYNC_FLUSH); in decompress_read()
202 ctx->eof = 1; in decompress_read()
207 if (ctx->zstr.avail_in == 0) { in decompress_read()
208 if (ctx->eof) { in decompress_read()
213 if ((n=zip_source_read(src, ctx->buffer, in decompress_read()
214 sizeof(ctx->buffer))) < 0) { in decompress_read()
215 zip_source_error(src, ctx->e, ctx->e+1); in decompress_read()
220 ctx->eof = 1; in decompress_read()
222 ctx->zstr.next_in = (Bytef *)ctx->buffer; in decompress_read()
223 ctx->zstr.avail_in = n; in decompress_read()
232 ctx->e[0] = ZIP_ER_ZLIB; in decompress_read()
233 ctx->e[1] = ret; in decompress_read()
239 if (ctx->zstr.avail_out < len) in decompress_read()
240 return len - ctx->zstr.avail_out; in decompress_read()
242 return (ctx->e[0] == 0) ? 0 : -1; in decompress_read()
251 struct deflate *ctx; in deflate_compress() local
254 ctx = (struct deflate *)ud; in deflate_compress()
258 ctx->zstr.zalloc = Z_NULL; in deflate_compress()
259 ctx->zstr.zfree = Z_NULL; in deflate_compress()
260 ctx->zstr.opaque = NULL; in deflate_compress()
261 ctx->zstr.avail_in = 0; in deflate_compress()
262 ctx->zstr.next_in = NULL; in deflate_compress()
263 ctx->zstr.avail_out = 0; in deflate_compress()
264 ctx->zstr.next_out = NULL; in deflate_compress()
267 if ((ret=deflateInit2(&ctx->zstr, Z_BEST_COMPRESSION, Z_DEFLATED, in deflate_compress()
268 -MAX_WBITS, ctx->mem_level, in deflate_compress()
270 ctx->e[0] = ZIP_ER_ZLIB; in deflate_compress()
271 ctx->e[1] = ret; in deflate_compress()
278 return compress_read(src, ctx, data, len); in deflate_compress()
281 deflateEnd(&ctx->zstr); in deflate_compress()
292 if (ctx->eof) { in deflate_compress()
293 st->comp_size = ctx->size; in deflate_compress()
302 memcpy(data, ctx->e, sizeof(int)*2); in deflate_compress()
306 deflate_free(ctx); in deflate_compress()
310 ctx->e[0] = ZIP_ER_INVAL; in deflate_compress()
311 ctx->e[1] = 0; in deflate_compress()
322 struct deflate *ctx; in deflate_decompress() local
326 ctx = (struct deflate *)ud; in deflate_decompress()
330 if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) in deflate_decompress()
333 ctx->zstr.zalloc = Z_NULL; in deflate_decompress()
334 ctx->zstr.zfree = Z_NULL; in deflate_decompress()
335 ctx->zstr.opaque = NULL; in deflate_decompress()
336 ctx->zstr.next_in = (Bytef *)ctx->buffer; in deflate_decompress()
337 ctx->zstr.avail_in = n; in deflate_decompress()
340 if ((ret=inflateInit2(&ctx->zstr, -MAX_WBITS)) != Z_OK) { in deflate_decompress()
341 ctx->e[0] = ZIP_ER_ZLIB; in deflate_decompress()
342 ctx->e[1] = ret; in deflate_decompress()
349 return decompress_read(src, ctx, data, len); in deflate_decompress()
352 inflateEnd(&ctx->zstr); in deflate_decompress()
371 memcpy(data, ctx->e, sizeof(int)*2); in deflate_decompress()
376 free(ctx); in deflate_decompress()
380 ctx->e[0] = ZIP_ER_INVAL; in deflate_decompress()
381 ctx->e[1] = 0; in deflate_decompress()
390 deflate_free(struct deflate *ctx) in deflate_free() argument
393 free(ctx); in deflate_free()