From bd6520d4ea3eb7c9c7a89df677a594e2d424f214 Mon Sep 17 00:00:00 2001
From: ellson <devnull@localhost>
Date: Tue, 9 Sep 2008 15:13:48 +0000
Subject: [PATCH] fix flushing of zlib buffers

---
 lib/gvc/gvdevice.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c
index 6c5088698..f01be80c1 100644
--- a/lib/gvc/gvdevice.c
+++ b/lib/gvc/gvdevice.c
@@ -283,9 +283,7 @@ static void gvdevice_flush(GVJ_t * job)
 {
     if (job->output_file
       && ! job->external_context
-      && ! job->gvc->write_fn
-      && job->output_lang != TK
-      && ! (job->flags & GVDEVICE_COMPRESSED_FORMAT)) {
+      && ! job->gvc->write_fn) {
 	fflush(job->output_file);
     }
 }
@@ -329,8 +327,12 @@ void gvdevice_finalize(GVJ_t * job)
 	z->avail_in = 0;
 	z->next_out = df;
 	z->avail_out = dfallocated;
-	ret = deflate (z, Z_FINISH);
-	if (ret != Z_STREAM_END && ret != Z_OK) {
+	while ((ret = deflate (z, Z_FINISH)) == Z_OK && (cnt++ <= 100)) {
+	    gvwrite_no_z(job, (char*)df, z->next_out - df);
+	    z->next_out = df;
+	    z->avail_out = dfallocated;
+	}
+	if (ret != Z_STREAM_END) {
             (job->common->errorfn) ("deflation finish problem %d cnt=%d\n", ret, cnt);
 	    exit(1);
 	}
-- 
2.40.0