Skip to content

Commit 195195a

Browse files
marc-hbnashif
authored andcommitted
file2hex.py: switch from gzip.compress() to GzipFile()
Zero functional change, this is pure refactoring and preparation for using the mtime= parameter which the gzip.compress() shortcut does not make available. Signed-off-by: Marc Herbert <[email protected]>
1 parent d3bb3cf commit 195195a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scripts/file2hex.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ def main():
4141
parse_args()
4242

4343
if args.gzip:
44-
with open(args.file, 'rb') as fg:
45-
content = io.BytesIO(gzip.compress(fg.read(), compresslevel=9))
44+
with io.BytesIO() as content:
45+
with open(args.file, 'rb') as fg:
46+
with gzip.GzipFile(fileobj=content, mode='w',
47+
compresslevel=9) as gz_obj:
48+
gz_obj.write(fg.read())
49+
50+
content.seek(0)
4651
for chunk in iter(lambda: content.read(8), b''):
4752
make_hex(chunk)
4853
else:

0 commit comments

Comments
 (0)