Skip to content

Commit 1c16221

Browse files
committed
Remove redundant crc32 function
1 parent b846d3a commit 1c16221

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/isal/igzip.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
Library to speed up its methods."""
2323

2424
import argparse
25-
import functools
2625
import gzip
2726
import io
2827
import os
29-
import _compression
3028
import sys
3129
from gzip import READ, WRITE
30+
31+
import _compression
32+
3233
from . import isal_zlib
3334

3435
__all__ = ["IGzipFile", "open", "compress", "decompress", "BadGzipFile"]
@@ -146,27 +147,20 @@ def write(self, data):
146147
return length
147148

148149

149-
# The gzip._GzipReader does all sorts of complex stuff. While using the
150-
# standard DecompressReader by _compression relies more on the C implementation
151-
# side of things. It is much simpler. Gzip header interpretation and gzip
152-
# checksum checking is already implemented in the isa-l library. So no need
153-
# to do so in pure python.
154150
class _IGzipReader(gzip._GzipReader):
155151
def __init__(self, fp):
156152
super().__init__(fp)
157153
self._decomp_factory = isal_zlib.decompressobj
158154
self._decomp_args = dict(wbits=64+isal_zlib.MAX_WBITS)
155+
# Set wbits such that ISAL_GZIP_NO_HDR_VER is used. This means that
156+
# it does not read a header, and it verifies the trailer.
159157
self._decompressor = self._decomp_factory(**self._decomp_args)
160158

161159
def _add_read_data(self, data):
162-
self._crc = isal_zlib.crc32(data, self._crc)
160+
# isa-l verifies the trailer data, so no need to keep track of the crc.
163161
self._stream_size = self._stream_size + len(data)
164162

165163
def _read_eof(self):
166-
crc32 = self._decompressor.crc
167-
if crc32 != self._crc:
168-
raise BadGzipFile(
169-
f"CRC check failed {hex(crc32)} != {hex(self._crc)}")
170164
# Gzip files can be padded with zeroes and still have archives.
171165
# Consume all zero bytes and set the file position to the first
172166
# non-zero byte. See http://www.gzip.org/#faq8

0 commit comments

Comments
 (0)