static int zlib_compress(gpr_slice_buffer* input, gpr_slice_buffer* output, int gzip) { z_stream zs; int r; size_t i; size_t count_before = output->count; size_t length_before = output->length; memset(&zs, 0, sizeof(zs)); r = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | (gzip ? 16 : 0), 8, Z_DEFAULT_STRATEGY); if (r != Z_OK) { gpr_log(GPR_ERROR, "deflateInit2 returns %d", r); return 0; } r = zlib_body(&zs, input, output, deflate) && output->length < input->length; if (!r) { for (i = count_before; i < output->count; i++) { gpr_slice_unref(output->slices[i]); } output->count = count_before; output->length = length_before; } deflateEnd(&zs); return r; }
static int zlib_compress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input, grpc_slice_buffer* output, int gzip) { z_stream zs; int r; size_t i; size_t count_before = output->count; size_t length_before = output->length; memset(&zs, 0, sizeof(zs)); zs.zalloc = zalloc_gpr; zs.zfree = zfree_gpr; r = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | (gzip ? 16 : 0), 8, Z_DEFAULT_STRATEGY); GPR_ASSERT(r == Z_OK); r = zlib_body(exec_ctx, &zs, input, output, deflate) && output->length < input->length; if (!r) { for (i = count_before; i < output->count; i++) { grpc_slice_unref_internal(exec_ctx, output->slices[i]); } output->count = count_before; output->length = length_before; } deflateEnd(&zs); return r; }
static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output, int gzip) { z_stream zs; int r; size_t i; size_t count_before = output->count; size_t length_before = output->length; memset(&zs, 0, sizeof(zs)); zs.zalloc = zalloc_gpr; zs.zfree = zfree_gpr; r = inflateInit2(&zs, 15 | (gzip ? 16 : 0)); GPR_ASSERT(r == Z_OK); r = zlib_body(&zs, input, output, inflate); if (!r) { for (i = count_before; i < output->count; i++) { grpc_slice_unref(output->slices[i]); } output->count = count_before; output->length = length_before; } inflateEnd(&zs); return r; }
static int zlib_decompress(gpr_slice_buffer* input, gpr_slice_buffer* output, int gzip) { z_stream zs; int r; size_t i; size_t count_before = output->count; size_t length_before = output->length; memset(&zs, 0, sizeof(zs)); r = inflateInit2(&zs, 15 | (gzip ? 16 : 0)); if (r != Z_OK) { gpr_log(GPR_ERROR, "inflateInit2 returns %d", r); return 0; } r = zlib_body(&zs, input, output, inflate); if (!r) { for (i = count_before; i < output->count; i++) { gpr_slice_unref(output->slices[i]); } output->count = count_before; output->length = length_before; } inflateEnd(&zs); return r; }