Skip to content

Instantly share code, notes, and snippets.

@davidbj
Created February 19, 2014 01:59
Show Gist options
  • Select an option

  • Save davidbj/9084706 to your computer and use it in GitHub Desktop.

Select an option

Save davidbj/9084706 to your computer and use it in GitHub Desktop.
I.Example of how to read a compressed file:
import gzip
f = gzip.open('file.tar.gz', 'rb')
file_content = f.read()
f.close()
II.Example of how to create a compressed GZIP file:
import gzip
content = 'Lots of content here'
f = gzip.open('file.txt.gz', 'wb')
f.write(content)
f.close()
III.Example of how to GZIP compress an existing file:
import gzip
f_in = open('file.txt', 'rb')
f_out = gzip.open('file.txt.gz', 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment