Skip to content

Commit f5a744a

Browse files
committed
Make sure header has reasonable values
1 parent 531d9b2 commit f5a744a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/isal/igzip.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ def __repr__(self):
123123
def flush(self, zlib_mode=isal_zlib.Z_SYNC_FLUSH):
124124
super().flush(zlib_mode)
125125

126+
def _write_gzip_header(self, compresslevel):
127+
# Determine what xfl flag is written for the compression level.
128+
# Equate the fast level to gzip level 1. All the other levels are
129+
# medium.
130+
if compresslevel == _COMPRESS_LEVEL_FAST:
131+
compresslevel = gzip._COMPRESS_LEVEL_FAST
132+
else:
133+
compresslevel = gzip._COMPRESS_LEVEL_TRADEOFF
134+
super()._write_gzip_header(compresslevel)
135+
126136
def write(self, data):
127137
self._check_not_closed()
128138
if self.mode != gzip.WRITE:

tests/test_gzip_compliance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ def test_compresslevel_metadata(self):
397397
# specifically, discussion of XFL in section 2.3.1
398398
cases = [
399399
('fast', 0, b'\x04'),
400-
('best', 3, b'\x02'),
401-
('tradeoff', 2, b'\x00'),
400+
('best', 3, b'\x00'), # Comparable to medium gzip level.
401+
('tradeoff', 2, b'\x00'), # Dito
402402
]
403403
xflOffset = 8
404404

0 commit comments

Comments
 (0)