From 1cdd461700e5595b3aff923164e577d7fb069f39 Mon Sep 17 00:00:00 2001 From: Thierry de Pauw Date: Sun, 3 Dec 2023 16:08:04 +0100 Subject: [PATCH] Extract decompression with zlib into GZipDecompressor._decompress_with_zlib (#18) --- DMARCReporting/decompressor.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/DMARCReporting/decompressor.py b/DMARCReporting/decompressor.py index 8897c0b..b009497 100644 --- a/DMARCReporting/decompressor.py +++ b/DMARCReporting/decompressor.py @@ -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():