Skip to content

Instantly share code, notes, and snippets.

@dmdavis
Created August 22, 2012 15:18
Show Gist options
  • Save dmdavis/3426680 to your computer and use it in GitHub Desktop.
Save dmdavis/3426680 to your computer and use it in GitHub Desktop.
Python: Compress a UTF-8 file using GZIP compression
def compress_utf8_file(fullpath, delete_original = True):
"""Compress a UTF-8 encoded file using GZIP compression named *.gz. If `delete_original` is `True` [default: True],
the original file specified by `delete_original` is removed after compression."""
with codecs.open(fullpath, 'r', 'utf-8') as fin:
with gzip.open(fullpath + '.gz', 'wb') as fout:
for line in fin:
fout.write(unicode(line).encode('utf-8'))
if delete_original:
os.remove(fullpath)
@youcantknow
Copy link

hmm

@goltsevnet
Copy link

hmm........

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment