@@ -282,32 +282,32 @@ def main():
282
282
283
283
compresslevel = args .compresslevel or _COMPRESS_LEVEL_TRADEOFF
284
284
285
- if args .file is None :
286
- if args .compress :
287
- in_file = sys .stdin .buffer
285
+ if args .compress and args .file is None :
286
+ in_file = sys .stdin .buffer
287
+ out_file = IGzipFile (mode = "wb" , compresslevel = compresslevel ,
288
+ fileobj = sys .stdout .buffer )
289
+ elif args .compress and args .file is not None :
290
+ in_file = io .open (args .file , mode = "rb" )
291
+ if args .stdout :
288
292
out_file = IGzipFile (mode = "wb" , compresslevel = compresslevel ,
289
293
fileobj = sys .stdout .buffer )
290
294
else :
291
- in_file = IGzipFile (mode = "rb" , fileobj = sys .stdin .buffer )
295
+ out_file = open (args .file + ".gz" , mode = "wb" ,
296
+ compresslevel = compresslevel )
297
+ elif not args .compress and args .file is None :
298
+ in_file = IGzipFile (mode = "rb" , fileobj = sys .stdin .buffer )
299
+ out_file = sys .stdout .buffer
300
+ elif not args .compress and args .file is not None :
301
+ if args .stdout :
292
302
out_file = sys .stdout .buffer
293
- else :
294
- if args .compress :
295
- in_file = io .open (args .file , mode = "rb" )
296
- if args .stdout :
297
- out_file = IGzipFile (mode = "wb" , compresslevel = compresslevel ,
298
- fileobj = sys .stdout .buffer )
299
- else :
300
- out_file = open (args .file + ".gz" , mode = "wb" ,
301
- compresslevel = compresslevel )
302
303
else :
303
304
base , extension = os .path .splitext (args .file )
304
305
if extension != ".gz" :
305
- raise ValueError (f"filename doesn't end in .gz: { args .file } " )
306
- in_file = open (args .file , "rb" )
307
- if args .stdout :
308
- out_file = sys .stdout .buffer
309
- else :
310
- out_file = io .open (base , "wb" )
306
+ raise ValueError (f"filename doesn't end in .gz: { args .file } . "
307
+ f"Cannot determine filename for output" )
308
+ out_file = io .open (base , "wb" )
309
+ in_file = open (args .file , "rb" )
310
+
311
311
try :
312
312
while True :
313
313
block = in_file .read (BUFFER_SIZE )
0 commit comments