summaryrefslogtreecommitdiff
path: root/kafka/codec.py
blob: 47ab074cf325e63657adf79b12f0d1780d308e92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from cStringIO import StringIO
import gzip
import logging

log = logging.getLogger("kafka.codec")

def gzip_encode(payload):
    buf = StringIO()
    f = gzip.GzipFile(fileobj=buf, mode='w', compresslevel=6)
    f.write(payload)
    f.close()
    buf.seek(0)
    out = buf.read()
    buf.close()
    return out

def gzip_decode(payload):
    buf = StringIO(payload)
    f = gzip.GzipFile(fileobj=buf, mode='r')
    out = f.read()
    f.close()
    buf.close()
    return out