67 enum { CHUNK = 16384 };
76 VERIFY3S(deflateInit(&strm, Z_DEFAULT_COMPRESSION), ==, Z_OK);
81 int have_in = MIN(len - consumed, CHUNK);
82 int have_out = len - output;
84 strm.next_in = in_buf + consumed;
85 strm.avail_in = have_in;
86 strm.next_out = out_buf + output;
87 strm.avail_out = have_out;
89 flush = (have_in == 0 ? Z_FINISH : Z_NO_FLUSH);
91 res = deflate(&strm, flush);
96 output += have_out - strm.avail_out;
98 if (res == Z_STREAM_END)
130 enum { OUT_BUF_SZ = 32768 };
132 void *out_buf = NULL;
133 size_t out_len = 0, out_cap = 0;
136 strm.zalloc = Z_NULL;
138 strm.opaque = Z_NULL;
139 strm.next_in = Z_NULL;
141 VERIFY3S(inflateInit(&strm), ==, Z_OK);
146 out_cap += OUT_BUF_SZ;
147 out_buf = realloc(out_buf, out_cap);
149 strm.next_in = in_buf + in_prog;
150 avail_in = len - in_prog;
151 strm.avail_in = avail_in;
152 strm.next_out = out_buf + out_len;
153 strm.avail_out = out_cap - out_len;
154 ret = inflate(&strm, Z_NO_FLUSH);
155 ASSERT(ret != Z_STREAM_ERROR);
167 in_prog += (avail_in - strm.avail_in);
168 out_len += (out_cap - out_len) - strm.avail_out;
169 if (ret == Z_STREAM_END)
175 *out_len_p = out_len;