raise CompressionError("zlib module is not available")
self.zlib = zlib
if mode == "r":
+ if self.enctype == 'aes':
+ self.encryption = aescrypto.AESCrypt(self.password,
+ key_length=self.key_length)
self._init_read_gz()
else:
self._init_write_gz()
self.__write_to_file(self.encryption.salt_str)
elif set_last_block_offset:
self.last_block_offset = self.fileobj.tell()
- self.fileobj
timestamp = struct.pack("<L", long(time.time()))
self.__write("\037\213\010\000%s\002\377" % timestamp)
"""
self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
- # if aes, we decrypt before the compression
- if self.enctype == 'aes':
- self.encryption = aescrypto.AESCrypt(self.password,
- key_length=self.key_length)
- self.encryption.get_salt(self.fileobj)
- self.encryption.init()
-
# taken from gzip.GzipFile with some alterations
read2 = self.__read(2)
if read2 != "\037\213":
buf = self.cmp.decompress(buf)
except IOError:
raise ReadError("invalid compressed data")
+ except Exception, e:
+ # happens at the end of the file
+ # _init_read_gz failed in the previous iteration so
+ # sel.cmp.descompress fails here
+ pass
if self.comptype == "gz" and hasattr(self, "crc"):
self.crc = self.zlib.crc32(buf, self.crc) & 0xffffffffL
else:
b1 = buf[:idx]
b2 = buf[idx:]
- buf = self.encryption.decrypt(b1, True)
+ if b1:
+ buf = self.encryption.decrypt(b1, True)
+ else:
+ buf = ''
self.encryption.get_salt_str(b2)
self.encryption.init()
b2 = b2[len(self.encryption.salt_str):]