def open_gzip_file(filename, mode, use_system=True):
"""Open a gzip file, preferring the system gzip program if `use_system`
is True, falling back to the gzip python library.
Args:
mode: The file open mode.
use_system: Whether to try to use the system gzip program.
"""
if use_system:
try:
if 'r' in mode:
gzfile = GzipReader(filename)
else:
gzfile = GzipWriter(filename)
if 't' in mode:
gzfile = io.TextIOWrapper(gzfile)
return gzfile
except:
pass
gzfile = gzip.open(filename, mode)
if 'b' in mode:
if 'r' in mode:
gzfile = io.BufferedReader(gzfile)
else:
gzfile = io.BufferedWriter(gzfile)
return gzfile
评论列表
文章目录