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