Skip to content

Commit

Permalink
Extract decompression with zlib into GZipDecompressor._decompress_wit…
Browse files Browse the repository at this point in the history
…h_zlib (#18)
  • Loading branch information
tdpauw committed Dec 3, 2023
1 parent de87f33 commit 1cdd461
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions DMARCReporting/decompressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ def decompress(self, gzip_file_path):
with gzip.open(gzip_file_path, 'rb') as f:
return f.read()
except gzip.BadGzipFile:
with open(gzip_file_path, 'rb') as f:
do = zlib.decompressobj(wbits=31)
data = do.decompress(f.read())
remainder = do.unused_data
f.seek(f.tell() - len(remainder))
return data
return self._decompress_with_zlib(gzip_file_path)

def _decompress_with_zlib(self, gzip_file_path):
with open(gzip_file_path, 'rb') as f:
do = zlib.decompressobj(wbits=31)
data = do.decompress(f.read())
remainder = do.unused_data
f.seek(f.tell() - len(remainder))
return data


class ZipDecompressor():
Expand Down

0 comments on commit 1cdd461

Please sign in to comment.