Skip to content

Commit 8686dee

Browse files
committed
Rework application
1 parent 4116c93 commit 8686dee

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/isal/igzip.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Library to speed up its methods."""
2323

2424
import argparse
25+
import functools
2526
import gzip
2627
import io
2728
import os
@@ -192,26 +193,22 @@ def main():
192193

193194
if args.compress:
194195
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
203198
else:
204199
base, extension = os.path.splitext(args.file)
205200
if extension != ".gz":
206201
raise ValueError("Can only decompress files with a .gz extension")
207202
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)
215212

216213

217214
if __name__ == "__main__":

0 commit comments

Comments
 (0)