gzip 

Send to Kindle
home » snippets » python » gzip



Snippets

# Simulate a string compressor / decompressor.

import cStringIO as StringIO
import gzip

def gzip_compress(s):
  sio = StringIO.StringIO()
  gf = gzip.GzipFile(compresslevel=1, mode="w", fileobj=sio)
  gf.write(s)
  gf.close()
  return sio.getvalue()

def gzip_decompress(s):
  sio = StringIO.StringIO(s)
  gf = gzip.GzipFile(mode="r", fileobj=sio)
  return gf.read(s)