@@ -434,6 +434,9 @@ def _argument_parser():
434
434
help = "Decompress the file instead of compressing." )
435
435
parser .add_argument ("-c" , "--stdout" , action = "store_true" ,
436
436
help = "write on standard output" )
437
+ parser .add_argument ("-o" , "--output" , help = "Write to this output file" )
438
+ parser .add_argument ("-f" , "--force" , action = "store_true" ,
439
+ help = "Overwrite output without prompting" )
437
440
# -b flag not taken by either gzip or igzip. Hidden attribute. Above 32K
438
441
# diminishing returns hit. _compression.BUFFER_SIZE = 8k. But 32K is about
439
442
# ~6% faster.
@@ -463,7 +466,18 @@ def main():
463
466
in_file = open (args .file , "rb" )
464
467
465
468
# Determine output file
466
- if args .compress and (args .file is None or args .stdout ):
469
+ if args .output is not None :
470
+ if os .path .exists (args .output ) and not args .force :
471
+ response = input (f"{ args .output } already exists; "
472
+ f"do you wish to overwrite (y/n)?" )
473
+ if response not in {"y" , "Y" }:
474
+ sys .exit ("not overwritten" )
475
+ if args .compress :
476
+ out_file = IGzipFile (args .output ,
477
+ mode = "wb" , compresslevel = compresslevel )
478
+ else :
479
+ out_file = io .open (args .output , "wb" )
480
+ elif args .compress and (args .file is None or args .stdout ):
467
481
out_file = IGzipFile (mode = "wb" , compresslevel = compresslevel ,
468
482
fileobj = sys .stdout .buffer )
469
483
elif args .compress and args .file is not None :
0 commit comments