def read_gzip(filepath):
# handles buffering # TODO: profile whether this is fast.
with gzip.open(filepath, 'rb') as f: # leave in binary mode (default), let TextIOWrapper decode
with io.BufferedReader(f, buffer_size=2**18) as g: # 256KB buffer
with io.TextIOWrapper(g) as h: # bytes -> unicode
yield h
评论列表
文章目录