Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def main():
compresslevel=compresslevel)
else:
f = builtins.open(arg, "rb")
g = open(arg + ".gz", "wb")
g = open(arg + ".gz", "wb", compresslevel=compresslevel)
while True:
chunk = f.read(READ_BUFFER_SIZE)
if not chunk:
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,8 @@ def test_compress_infile_outfile_default(self):

@create_and_remove_directory(TEMPDIR)
def test_compress_infile_outfile(self):
for compress_level in ('--fast', '--best'):
# The XFL header byte records the compression level used.
for compress_level, xfl in (('--fast', 4), ('--best', 2)):
with self.subTest(compress_level=compress_level):
local_testgzip = os.path.join(TEMPDIR, 'testgzip')
gzipname = local_testgzip + '.gz'
Expand All @@ -1243,6 +1244,8 @@ def test_compress_infile_outfile(self):
self.assertTrue(os.path.exists(gzipname))
self.assertEqual(out, b'')
self.assertEqual(err, b'')
with open(gzipname, 'rb') as fp:
self.assertEqual(fp.read()[8], xfl)
os.remove(gzipname)
self.assertFalse(os.path.exists(gzipname))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the :mod:`gzip` command-line interface ignoring :option:`gzip --fast`
and :option:`gzip --best` when compressing files given as arguments.
Loading