Permalink
Browse files

[gzip] Allow partial flush

	When Flush() is called explicitly, do a Z_PARTIAL_FLUSH to force gzip
	into giving us whatever is available. Less efficient, but compatible
	with MS.
  • Loading branch information...
1 parent c365c9a commit 64a750eff3f8e676dcbb793785053991acbc731b @gonzalop gonzalop committed Feb 12, 2011
Showing with 18 additions and 4 deletions.
  1. +18 −4 support/zlib-helper.c
View
@@ -42,6 +42,7 @@ gint CloseZStream (ZStream *zstream);
gint Flush (ZStream *stream);
gint ReadZStream (ZStream *stream, guchar *buffer, gint length);
gint WriteZStream (ZStream *stream, guchar *buffer, gint length);
+static gint flush_internal (ZStream *stream, gboolean is_final);
static void *
z_alloc (void *opaque, gsize nitems, gsize item_size)
@@ -106,7 +107,7 @@ CloseZStream (ZStream *zstream)
if (zstream->stream->total_in > 0) {
do {
status = deflate (zstream->stream, Z_FINISH);
- flush_status = Flush (zstream);
+ flush_status = flush_internal (zstream, TRUE);
} while (status == Z_OK); /* We want Z_STREAM_END or error here here */
if (status == Z_STREAM_END)
status = flush_status;
@@ -132,23 +133,36 @@ write_to_managed (ZStream *stream)
if (zs->avail_out != BUFFER_SIZE) {
n = stream->func (stream->buffer, BUFFER_SIZE - zs->avail_out, stream->gchandle);
zs->next_out = stream->buffer;
- zs->avail_out = BUFFER_SIZE;
+ zs->avail_out = BUFFER_SIZE;
if (n < 0)
return IO_ERROR;
}
return 0;
}
-gint
-Flush (ZStream *stream)
+static gint
+flush_internal (ZStream *stream, gboolean is_final)
{
+ gint status;
+
if (!stream->compress)
return 0;
+ if (!is_final) {
+ status = deflate (stream->stream, Z_PARTIAL_FLUSH);
+ if (status != Z_OK && status != Z_STREAM_END)
+ return status;
+ }
return write_to_managed (stream);
}
gint
+Flush (ZStream *stream)
+{
+ return flush_internal (stream, FALSE);
+}
+
+gint
ReadZStream (ZStream *stream, guchar *buffer, gint length)
{
gint n;

0 comments on commit 64a750e

Please sign in to comment.