Lines Matching refs:zstream
33 struct zlib_ostream *zstream = (struct zlib_ostream *)stream;
35 i_assert(zstream->ostream.finished ||
36 zstream->ostream.ostream.stream_errno != 0 ||
37 zstream->ostream.error_handling_disabled);
38 (void)deflateEnd(&zstream->zs);
40 o_stream_close(zstream->ostream.parent);
43 static int o_stream_zlib_send_gz_header(struct zlib_ostream *zstream)
47 ret = o_stream_send(zstream->ostream.parent, zstream->gz_header,
48 sizeof(zstream->gz_header));
49 if ((size_t)ret != sizeof(zstream->gz_header)) {
50 o_stream_copy_error_from_parent(&zstream->ostream);
53 zstream->header_sent = TRUE;
71 static int o_stream_zlib_send_gz_trailer(struct zlib_ostream *zstream)
73 struct ostream *output = zstream->ostream.parent;
75 if (!zstream->gz)
78 if (o_stream_zlib_lsb_uint32(output, zstream->crc) < 0 ||
79 o_stream_zlib_lsb_uint32(output, zstream->bytes32) < 0) {
80 o_stream_copy_error_from_parent(&zstream->ostream);
86 static int o_stream_zlib_send_outbuf(struct zlib_ostream *zstream)
91 if (zstream->outbuf_used == 0)
94 size = zstream->outbuf_used - zstream->outbuf_offset;
96 ret = o_stream_send(zstream->ostream.parent,
97 zstream->outbuf + zstream->outbuf_offset, size);
99 o_stream_copy_error_from_parent(&zstream->ostream);
103 zstream->outbuf_offset += ret;
106 zstream->outbuf_offset = 0;
107 zstream->outbuf_used = 0;
112 o_stream_zlib_send_chunk(struct zlib_ostream *zstream,
115 z_stream *zs = &zstream->zs;
118 i_assert(zstream->outbuf_used == 0);
120 flush = zstream->ostream.corked || zstream->gz ?
123 if (!zstream->header_sent) {
124 if (o_stream_zlib_send_gz_header(zstream) < 0)
134 zs->next_out = zstream->outbuf;
135 zs->avail_out = sizeof(zstream->outbuf);
137 zstream->outbuf_used = sizeof(zstream->outbuf);
138 if ((ret = o_stream_zlib_send_outbuf(zstream)) < 0)
152 i_assert(zstream->gz);
154 o_stream_get_name(&zstream->ostream.ostream));
157 o_stream_get_name(&zstream->ostream.ostream), ret);
162 zstream->crc = crc32_data_more(zstream->crc, data, size);
163 zstream->bytes32 += size;
164 zstream->flushed = flush == Z_SYNC_FLUSH && zs->avail_in == 0 &&
165 zs->avail_out == sizeof(zstream->outbuf);
170 o_stream_zlib_send_flush(struct zlib_ostream *zstream, bool final)
172 z_stream *zs = &zstream->zs;
179 if (zstream->flushed)
182 if ((ret = o_stream_flush_parent_if_needed(&zstream->ostream)) <= 0)
184 if (!zstream->header_sent) {
185 if (o_stream_zlib_send_gz_header(zstream) < 0)
189 if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0)
192 flush = !zstream->gz ? Z_SYNC_FLUSH :
195 i_assert(zstream->outbuf_used == 0);
197 len = sizeof(zstream->outbuf) - zs->avail_out;
199 zs->next_out = zstream->outbuf;
200 zs->avail_out = sizeof(zstream->outbuf);
202 zstream->outbuf_used = len;
203 if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0)
219 } while (zs->avail_out != sizeof(zstream->outbuf));
222 if (o_stream_zlib_send_gz_trailer(zstream) < 0)
226 zstream->flushed = TRUE;
232 struct zlib_ostream *zstream = (struct zlib_ostream *)stream;
234 if (o_stream_zlib_send_flush(zstream, stream->finished) < 0)
244 struct zlib_ostream *zstream = (struct zlib_ostream *)stream;
248 if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0) {
255 ret = o_stream_zlib_send_chunk(zstream, iov[i].iov_base,
265 if (!zstream->ostream.corked && i == iov_count) {
266 if (o_stream_zlib_send_flush(zstream, FALSE) < 0)
271 zstream->zs.avail_in = 0;
275 static void o_stream_zlib_init_gz_header(struct zlib_ostream *zstream,
278 unsigned char *hdr = zstream->gz_header;
287 i_assert(sizeof(zstream->gz_header) == 10);
294 struct zlib_ostream *zstream;
299 zstream = i_new(struct zlib_ostream, 1);
300 zstream->ostream.sendv = o_stream_zlib_sendv;
301 zstream->ostream.flush = o_stream_zlib_flush;
302 zstream->ostream.iostream.close = o_stream_zlib_close;
303 zstream->crc = 0;
304 zstream->gz = gz;
306 zstream->header_sent = TRUE;
308 o_stream_zlib_init_gz_header(zstream, level, strategy);
309 ret = deflateInit2(&zstream->zs, level, Z_DEFLATED, -15, 8, strategy);
323 zstream->zs.next_out = zstream->outbuf;
324 zstream->zs.avail_out = sizeof(zstream->outbuf);
325 return o_stream_create(&zstream->ostream, output,