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
相關文章
相關標籤/搜索