压缩
def gzip_compress(buf, compresslevel=6):
out = StringIO.StringIO()
f = gzip.GzipFile(fileobj=out, mode="w", compresslevel=compresslevel)
f.write(buf)
f.close()
res = out.getvalue()
return res
解压缩
def gzip_decompress(buf):
obj = StringIO.StringIO(buf)
f = gzip.GzipFile(fileobj=obj)
result = f.read()
f.close()
return result