File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change 22
22
Library to speed up its methods."""
23
23
24
24
import argparse
25
+ import functools
25
26
import gzip
26
27
import io
27
28
import os
@@ -192,26 +193,22 @@ def main():
192
193
193
194
if args .compress :
194
195
out_filename = args .file + ".gz"
195
- with io .open (args .file , "rb" ) as in_file :
196
- with open (out_filename , mode = "rb" , compresslevel = compresslevel
197
- ) as out_file :
198
- while True :
199
- block = in_file .read (_BLOCK_SIZE )
200
- if block == b"" :
201
- break
202
- out_file .write (block )
196
+ out_open = functools .partial (open , compresslevel = compresslevel )
197
+ in_open = io .open
203
198
else :
204
199
base , extension = os .path .splitext (args .file )
205
200
if extension != ".gz" :
206
201
raise ValueError ("Can only decompress files with a .gz extension" )
207
202
out_filename = base
208
- with open (args .file , "rb" ) as in_file :
209
- with io .open (out_filename , mode = "rb" ) as out_file :
210
- while True :
211
- block = in_file .read (_BLOCK_SIZE )
212
- if block == b"" :
213
- break
214
- out_file .write (block )
203
+ out_open = io .open
204
+ in_open = open
205
+ with in_open (args .file , "rb" ) as in_file :
206
+ with out_open (out_filename , "wb" ) as out_file :
207
+ while True :
208
+ block = in_file .read (_BLOCK_SIZE )
209
+ if block == b"" :
210
+ break
211
+ out_file .write (block )
215
212
216
213
217
214
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments