Lines Matching refs:ctx

62     struct deflate *ctx;  in zip_source_deflate()  local
70 if ((ctx=(struct deflate *)malloc(sizeof(*ctx))) == NULL) { in zip_source_deflate()
75 zip_error_init(&ctx->error); in zip_source_deflate()
76 ctx->eof = false; in zip_source_deflate()
77 ctx->is_stored = false; in zip_source_deflate()
78 ctx->can_store = ZIP_CM_IS_DEFAULT(cm); in zip_source_deflate()
80 ctx->mem_level = MAX_MEM_LEVEL; in zip_source_deflate()
86 ctx)) == NULL) { in zip_source_deflate()
87 deflate_free(ctx); in zip_source_deflate()
96 compress_read(zip_source_t *src, struct deflate *ctx, void *data, zip_uint64_t len) in compress_read() argument
103 if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) in compress_read()
106 if (len == 0 || ctx->is_stored) { in compress_read()
112 ctx->zstr.next_out = (Bytef *)data; in compress_read()
113 ctx->zstr.avail_out = out_len; in compress_read()
117 ret = deflate(&ctx->zstr, ctx->eof ? Z_FINISH : 0); in compress_read()
121 if (ctx->can_store && ctx->zstr.total_in <= ctx->zstr.total_out) { in compress_read()
122 ctx->is_stored = true; in compress_read()
123 ctx->size = ctx->zstr.total_in; in compress_read()
124 memcpy(data, ctx->buffer, ctx->size); in compress_read()
125 return (zip_int64_t)ctx->size; in compress_read()
131 if (ctx->zstr.avail_out == 0) { in compress_read()
135 ctx->zstr.next_out = (Bytef *)data+out_offset; in compress_read()
136 ctx->zstr.avail_out = out_len; in compress_read()
139 ctx->can_store = false; in compress_read()
143 else if (ctx->eof && ctx->zstr.avail_in == 0) in compress_read()
148 if (ctx->zstr.avail_in == 0) { in compress_read()
149 if (ctx->eof) { in compress_read()
154 if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) { in compress_read()
155 _zip_error_set_from_source(&ctx->error, src); in compress_read()
160 ctx->eof = true; in compress_read()
162 ctx->size = ctx->zstr.total_in; in compress_read()
165 if (ctx->zstr.total_in > 0) { in compress_read()
167 ctx->can_store = false; in compress_read()
169 ctx->zstr.next_in = (Bytef *)ctx->buffer; in compress_read()
170 ctx->zstr.avail_in = (uInt)n; in compress_read()
179 zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); in compress_read()
186 if (ctx->zstr.avail_out < len) { in compress_read()
187 ctx->can_store = false; in compress_read()
188 return (zip_int64_t)(len - ctx->zstr.avail_out); in compress_read()
191 return (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) ? 0 : -1; in compress_read()
196 decompress_read(zip_source_t *src, struct deflate *ctx, void *data, zip_uint64_t len) in decompress_read() argument
203 if (zip_error_code_zip(&ctx->error) != ZIP_ER_OK) in decompress_read()
211 ctx->zstr.next_out = (Bytef *)data; in decompress_read()
212 ctx->zstr.avail_out = out_len; in decompress_read()
216 ret = inflate(&ctx->zstr, Z_SYNC_FLUSH); in decompress_read()
220 if (ctx->zstr.avail_out == 0) { in decompress_read()
224 ctx->zstr.next_out = (Bytef *)data+out_offset; in decompress_read()
225 ctx->zstr.avail_out = out_len; in decompress_read()
234 ctx->eof = 1; in decompress_read()
239 if (ctx->zstr.avail_in == 0) { in decompress_read()
240 if (ctx->eof) { in decompress_read()
245 if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) { in decompress_read()
246 _zip_error_set_from_source(&ctx->error, src); in decompress_read()
251 ctx->eof = 1; in decompress_read()
254 ctx->zstr.next_in = (Bytef *)ctx->buffer; in decompress_read()
255 ctx->zstr.avail_in = (uInt)n; in decompress_read()
264 zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); in decompress_read()
270 if (ctx->zstr.avail_out < len) in decompress_read()
271 return (zip_int64_t)(len - ctx->zstr.avail_out); in decompress_read()
273 return (zip_error_code_zip(&ctx->error) == ZIP_ER_OK) ? 0 : -1; in decompress_read()
280 struct deflate *ctx; in deflate_compress() local
283 ctx = (struct deflate *)ud; in deflate_compress()
287 ctx->zstr.zalloc = Z_NULL; in deflate_compress()
288 ctx->zstr.zfree = Z_NULL; in deflate_compress()
289 ctx->zstr.opaque = NULL; in deflate_compress()
290 ctx->zstr.avail_in = 0; in deflate_compress()
291 ctx->zstr.next_in = NULL; in deflate_compress()
292 ctx->zstr.avail_out = 0; in deflate_compress()
293 ctx->zstr.next_out = NULL; in deflate_compress()
296 …if ((ret=deflateInit2(&ctx->zstr, Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS, ctx->mem_level, Z_DE… in deflate_compress()
297 zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); in deflate_compress()
304 return compress_read(src, ctx, data, len); in deflate_compress()
307 deflateEnd(&ctx->zstr); in deflate_compress()
316 st->comp_method = ctx->is_stored ? ZIP_CM_STORE : ZIP_CM_DEFLATE; in deflate_compress()
318 if (ctx->eof) { in deflate_compress()
319 st->comp_size = ctx->size; in deflate_compress()
328 return zip_error_to_data(&ctx->error, data, len); in deflate_compress()
331 deflate_free(ctx); in deflate_compress()
338 zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0); in deflate_compress()
348 struct deflate *ctx; in deflate_decompress() local
352 ctx = (struct deflate *)ud; in deflate_decompress()
356 if ((n=zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) { in deflate_decompress()
357 _zip_error_set_from_source(&ctx->error, src); in deflate_decompress()
361 ctx->zstr.zalloc = Z_NULL; in deflate_decompress()
362 ctx->zstr.zfree = Z_NULL; in deflate_decompress()
363 ctx->zstr.opaque = NULL; in deflate_decompress()
364 ctx->zstr.next_in = (Bytef *)ctx->buffer; in deflate_decompress()
365 ctx->zstr.avail_in = (uInt)n; in deflate_decompress()
368 if ((ret=inflateInit2(&ctx->zstr, -MAX_WBITS)) != Z_OK) { in deflate_decompress()
369 zip_error_set(&ctx->error, ZIP_ER_ZLIB, ret); in deflate_decompress()
375 return decompress_read(src, ctx, data, len); in deflate_decompress()
378 inflateEnd(&ctx->zstr); in deflate_decompress()
395 return zip_error_to_data(&ctx->error, data, len); in deflate_decompress()
398 free(ctx); in deflate_decompress()
405 zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0); in deflate_decompress()
412 deflate_free(struct deflate *ctx) in deflate_free() argument
414 free(ctx); in deflate_free()