static gint flush_internal (ZStream *stream, gboolean is_final);
static void *
-z_alloc (void *opaque, gsize nitems, gsize item_size)
+z_alloc (void *opaque, unsigned int nitems, unsigned int item_size)
{
return g_malloc0 (nitems * item_size);
}
result->gchandle = gchandle;
result->compress = compress;
result->buffer = g_new (guchar, BUFFER_SIZE);
+ result->stream->next_out = result->buffer;
+ result->stream->avail_out = BUFFER_SIZE;
return result;
}
if (!stream->compress)
return 0;
- if (!is_final) {
+ if (!is_final && stream->stream->avail_in != 0) {
status = deflate (stream->stream, Z_PARTIAL_FLUSH);
if (status != Z_OK && status != Z_STREAM_END)
return status;
stream->eof = TRUE;
}
zs->next_in = stream->buffer;
- zs->avail_in = n;
+ zs->avail_in = n < 0 ? 0 : n;
}
+ if (zs->avail_in == 0 && zs->total_in == 0)
+ return Z_STREAM_END;
+
status = inflate (stream->stream, Z_SYNC_FLUSH);
if (status == Z_STREAM_END) {
stream->eof = TRUE;