From af4361b10790276f63942df98ec43a1e7046b2cd Mon Sep 17 00:00:00 2001 From: palkeo Date: Thu, 20 Nov 2014 22:17:04 -0300 Subject: [PATCH] Correct a bug occurring when the underlying file object is filling very fast. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible that « unused_raw » contains more than one end of stream and start of another. We need to restart the decoder while there are unused data at the end. This caused a strange bug when using that to stream a commoncrawl archive on my server with a good bandwidth, that don't happened on my test computer : zlib.error: Error -3 while decompressing: incorrect header check (in restart_decoder). --- gzipstream/gzipstreamfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gzipstream/gzipstreamfile.py b/gzipstream/gzipstreamfile.py index 9e6f2eb..31b3c71 100644 --- a/gzipstream/gzipstreamfile.py +++ b/gzipstream/gzipstreamfile.py @@ -22,7 +22,7 @@ def read(self, size): # TODO: Update this to use unconsumed_tail and a StringIO buffer # http://docs.python.org/2/library/zlib.html#zlib.Decompress.unconsumed_tail # Check if we need to start a new decoder - if self.decoder and self.decoder.unused_data: + while self.decoder and self.decoder.unused_data: self.restart_decoder() # Use unused data first if len(self.unused_buffer) > size: