Skip to content

Commit

Permalink
We have to wrap gzip filse in io.TextIOWrapper if using text mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenxxiu committed Jan 6, 2020
1 parent 341c2a4 commit f5390b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/cfv/fileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ def open_write(filename, config):

if config.gzip >= 2 or (config.gzip >= 0 and filename[-3:].lower() == '.gz'):
import gzip
import io
if filename == '-':
return gzip.GzipFile(filename=filename, mode=mode, fileobj=sys.stdout)
return gzip.open(filename, mode)
res = gzip.GzipFile(filename=filename, mode=mode, fileobj=sys.stdout)
else:
res = gzip.open(filename, mode)
if mode == 'w':
res = io.TextIOWrapper(res, encoding=encoding)
return res
else:
if filename == '-':
return NoCloseFile(sys.stdout)
Expand Down

0 comments on commit f5390b8

Please sign in to comment.