avoid to use zlib when the compress type is not ZIP_DEFLATED

This commit is contained in:
Ezio Melotti 2010-01-28 01:41:30 +00:00
parent 9ef7d4f73c
commit 4611b05bd8
1 changed files with 8 additions and 6 deletions

View File

@ -471,6 +471,11 @@ class ZipExtFile(io.BufferedIOBase):
self._fileobj = fileobj self._fileobj = fileobj
self._decrypter = decrypter self._decrypter = decrypter
self._compress_type = zipinfo.compress_type
self._compress_size = zipinfo.compress_size
self._compress_left = zipinfo.compress_size
if self._compress_type == ZIP_DEFLATED:
self._decompressor = zlib.decompressobj(-15) self._decompressor = zlib.decompressobj(-15)
self._unconsumed = '' self._unconsumed = ''
@ -480,10 +485,6 @@ class ZipExtFile(io.BufferedIOBase):
self._universal = 'U' in mode self._universal = 'U' in mode
self.newlines = None self.newlines = None
self._compress_type = zipinfo.compress_type
self._compress_size = zipinfo.compress_size
self._compress_left = zipinfo.compress_size
# Adjust read size for encrypted files since the first 12 bytes # Adjust read size for encrypted files since the first 12 bytes
# are for the encryption/password information. # are for the encryption/password information.
if self._decrypter is not None: if self._decrypter is not None:
@ -599,7 +600,8 @@ class ZipExtFile(io.BufferedIOBase):
self._unconsumed += data self._unconsumed += data
# Handle unconsumed data. # Handle unconsumed data.
if len(self._unconsumed) > 0 and n > len_readbuffer: if (len(self._unconsumed) > 0 and n > len_readbuffer and
self._compress_type == ZIP_DEFLATED):
data = self._decompressor.decompress( data = self._decompressor.decompress(
self._unconsumed, self._unconsumed,
max(n - len_readbuffer, self.MIN_READ_SIZE) max(n - len_readbuffer, self.MIN_READ_SIZE)