Skip to content

Commit

Permalink
Improve DecompressChain logics
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Aug 1, 2020
1 parent 030293e commit 27f6c17
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions py7zr/compressor.py
Expand Up @@ -633,6 +633,7 @@ def decompress(self, data, max_length=0):
if max_length == 0:
res = self._buf + self._decompress(self._unused + data)
self._buf = bytearray()
self._unused = bytearray()
else:
current_buf_len = len(self._buf)
if current_buf_len >= max_length:
Expand All @@ -645,8 +646,12 @@ def decompress(self, data, max_length=0):
self._unused = bytearray()
else:
tmp = self._decompress(data)
res = self._buf + tmp[:max_length - current_buf_len]
self._buf = bytearray(tmp[max_length - current_buf_len:])
if current_buf_len + len(tmp) <= max_length:
res = self._buf + tmp
self._buf = bytearray()
else:
res = self._buf + tmp[:max_length - current_buf_len]
self._buf = bytearray(tmp[max_length - current_buf_len:])
return res

@property
Expand Down

0 comments on commit 27f6c17

Please sign in to comment.