python gzip 压缩/解压缩 字符串

python gzip 压缩/解压缩 字符串

  • 参考文章

import gzip
import StringIO


def gzip_compress(buf):
    out = StringIO.StringIO()
    with gzip.GzipFile(fileobj=out, mode="w") as f:
        f.write(buf)
    return out.getvalue()


def gzip_decompress(buf):
    obj = StringIO.StringIO(buf)
    with gzip.GzipFile(fileobj=obj) as f:
        result = f.read()
    return result

参考文章

http://www.voidcn.com/article/p-wjfddsdx-bre.html

你可能感兴趣的:(编程开发)