From f21bdb4c25052b259c16736558d58c402f104be9 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 27 Sep 2006 19:37:27 +0000 Subject: [PATCH] [Backport rev. 38534 by loewis] [Possibly controversial because it adds a parameter to a method. This parameter isn't documented, however, so arguably it's a private detail, and the fix is necessary to make GzipFile.flush() behave more similarly to regular file object.] Patch #1110248: SYNC_FLUSH the zlib buffer for GZipFile.flush. Partially fixes #1110242. --- Lib/gzip.py | 5 ++++- Misc/NEWS | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index cec8c0eead1e..ecfd98cb459e 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -332,7 +332,10 @@ class GzipFile: return self.close() - def flush(self): + def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH): + if self.mode == WRITE: + # Ensure the compressor's buffer is flushed + self.fileobj.write(self.compress.flush(zlib_mode)) self.fileobj.flush() def fileno(self): diff --git a/Misc/NEWS b/Misc/NEWS index b966fae786c3..28bc76a973e5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -176,6 +176,7 @@ Library - Bug #1472827: correctly escape newlines and tabs in attribute values in the saxutils.XMLGenerator class. +- Patch #1110248: SYNC_FLUSH the zlib buffer for GZipFile.flush. Tools/Demos ----------- -- 2.47.3