@@ -434,6 +434,9 @@ def _argument_parser():
434434 help = "Decompress the file instead of compressing." )
435435 parser .add_argument ("-c" , "--stdout" , action = "store_true" ,
436436 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" )
437440 # -b flag not taken by either gzip or igzip. Hidden attribute. Above 32K
438441 # diminishing returns hit. _compression.BUFFER_SIZE = 8k. But 32K is about
439442 # ~6% faster.
@@ -463,7 +466,18 @@ def main():
463466 in_file = open (args .file , "rb" )
464467
465468 # 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 ):
467481 out_file = IGzipFile (mode = "wb" , compresslevel = compresslevel ,
468482 fileobj = sys .stdout .buffer )
469483 elif args .compress and args .file is not None :
0 commit comments