This seems to be a copy&paste oversight from
commit
be60ffd0598fec172eccb69f3c6a8433af6fb643
Author: Eduardo Robles Elvira <edulix@wadobo.com>
Date: Mon Nov 4 08:50:55 2013 +0100
initial port to python 3, not finished
which added the per-compression mode exceptions but not the
actual handling code.
self.concat_stream = concat_stream
self.last_block_offset = 0
self.dbuf = b"" # ???
- self.exception = None
+ self.exception = None # communicate decompression failure
self.compresslevel = compresslevel
self.bytes_written = 0
# crypto parameters
if concat_stream is False:
if mode == "r":
self._init_read_gz()
- self.exception = zlib.error
elif mode == "w":
self._new_gz_block()
self.crc = zlib.crc32(b"") & 0xFFFFffff
+ if mode == "r":
+ self.exception = zlib.error
elif comptype == "bz2":
if self.encryption is not None:
if self.cmp is not None:
try:
buf = self.cmp.decompress(buf)
- except OSError:
+ except self.exception:
raise ReadError("invalid compressed data")
except Exception as e:
# happens at the end of the file