Skip to content
Snippets Groups Projects
Commit d39b1cbf authored by Yohan Jarosz's avatar Yohan Jarosz
Browse files

add possibility to uncompress bz2 files - fix #25

parent 5fbdd577
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import os
import shutil
import gzip
import json
import bz2
from copy import deepcopy
......
......@@ -8,6 +8,9 @@ include:
"MT.rules"
CHUNK_SIZE = 100 * 1024
def preprocessing_output_files():
"""
Dynamically generate output files names based on parameters
......@@ -74,10 +77,15 @@ def prepare_input_files(input, rtype):
print(inp, '=>', outfilename)
# ungunzip
if os.path.splitext(fname)[-1] in ['.gz', '.gzip']:
with open(outfilename, 'wb') as whandle:
with gzip.open(inp, 'rb') as rhandle:
whandle.write(rhandle.read())
# copy
with open(outfilename, 'wb') as whandle, gzip.open(inp, 'rb') as rhandle:
whandle.write(rhandle.read())
# unbzip2
elif os.path.splitext(fname)[-1] in ['.bz2', '.bzip2']:
dec = bz2.BZ2Decompressor()
with open(outfilename, 'wb') as whandle, open(inp, 'rb') as rhandle:
for data in iter(lambda: rhandle.read(CHUNK_SIZE), b''):
whandle.write(dec.decompress(data))
# copy
else:
shutil.copy(inp, outfilename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment