def decompress(fname, remove_compressed=True):
"""
Decompress *fname* and return the file name without the
compression suffix, e.g., .gz. If *remove_compressed*, the
compressed file is deleted after it is decompressed.
"""
if fname.endswith('.gz'):
uncompressed_fname = fname[:-3]
logger.info('gunzip {} to {}'.format(fname, uncompressed_fname))
with gzip.open(fname) as in_fid, open(uncompressed_fname, 'w') as out_fid:
shutil.copyfileobj(in_fid, out_fid)
if remove_compressed:
logger.debug('removing {}'.format(fname))
os.remove(fname)
return uncompressed_fname
else:
return fname
评论列表
文章目录