SimpleDao

压缩

  1. def gzip_compress(buf, compresslevel=6):
  2. out = StringIO.StringIO()
  3. f = gzip.GzipFile(fileobj=out, mode="w", compresslevel=compresslevel)
  4. f.write(buf)
  5. f.close()
  6. res = out.getvalue()
  7. return res

解压缩

  1. def gzip_decompress(buf):
  2. obj = StringIO.StringIO(buf)
  3. f = gzip.GzipFile(fileobj=obj)
  4. result = f.read()
  5. f.close()
  6. return result