Skip to content

Commit e4a04d5

Browse files
authored
Merge pull request #111 from pycompression/noname
Add --no-name flag.
2 parents d8ff261 + c503450 commit e4a04d5

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ that PyPy is no longer supported.
2222
for decompressing gzip files. PyPy should not be used for workloads that
2323
require heavy zlib-compatible compression/decompression. As such it was
2424
deemed unnecessary to continue supporting PyPy.
25+
+ A ``--no-name`` flag has been added to ``python -m isal.igzip``.
2526
+ Cython is no longer required as a build dependency.
2627
+ a fast function calling method ``METH_FASTCALL`` is now used to call the
2728
functions. This method is only supported by Python 3.7 and higher. This has

src/isal/igzip.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ def _argument_parser():
442442
help="write on standard output")
443443
output_group.add_argument("-o", "--output",
444444
help="Write to this output file")
445+
parser.add_argument("-n", "--no-name", action="store_true",
446+
dest="reproducible",
447+
help="do not save or restore the original name and "
448+
"timestamp")
445449
parser.add_argument("-f", "--force", action="store_true",
446450
help="Overwrite output without prompting")
447451
# -b flag not taken by either gzip or igzip. Hidden attribute. Above 32K
@@ -485,10 +489,16 @@ def main():
485489
else:
486490
in_file = io.open(args.file, mode="rb")
487491
if out_filepath is not None:
488-
out_file = open(out_filepath, "wb", compresslevel=compresslevel)
492+
out_buffer = io.open(out_filepath, "wb")
489493
else:
490-
out_file = IGzipFile(mode="wb", fileobj=sys.stdout.buffer,
491-
compresslevel=compresslevel)
494+
out_buffer = sys.stdout.buffer
495+
496+
if args.reproducible:
497+
gzip_file_kwargs = {"mtime": 0, "filename": b""}
498+
else:
499+
gzip_file_kwargs = {"filename": out_filepath}
500+
out_file = IGzipFile(mode="wb", fileobj=out_buffer,
501+
compresslevel=compresslevel, **gzip_file_kwargs)
492502
else:
493503
if args.file:
494504
in_file = open(args.file, mode="rb")

tests/test_igzip.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,21 @@ def test_compress_infile_out_file_inmplicit_name_prompt_accept(
222222
assert err == b""
223223

224224

225+
def test_compress_infile_out_file_no_name(tmp_path, capsysbinary):
226+
test = tmp_path / "test"
227+
test.write_bytes(DATA)
228+
out_file = tmp_path / "compressed.gz"
229+
sys.argv = ['', '-n', '-o', str(out_file), str(test)]
230+
igzip.main()
231+
out, err = capsysbinary.readouterr()
232+
output = out_file.read_bytes()
233+
assert gzip.decompress(output) == DATA
234+
assert err == b''
235+
assert out == b''
236+
assert output[4] & gzip.FNAME == 0 # No filename set.
237+
assert output[4:8] == b"\x00\x00\x00\x00" # No timestamp set.
238+
239+
225240
def test_decompress():
226241
assert igzip.decompress(COMPRESSED_DATA) == DATA
227242

0 commit comments

Comments
 (0)