From c99d4119f2d6d0fdee38a159e1c845e42cf398b1 Mon Sep 17 00:00:00 2001 From: David Arthur Date: Tue, 2 Oct 2012 12:14:48 -0400 Subject: Moved codec stuff into it's own module Snappy will go there when I get around to it --- kafka/codec.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 kafka/codec.py (limited to 'kafka/codec.py') diff --git a/kafka/codec.py b/kafka/codec.py new file mode 100644 index 0000000..47ab074 --- /dev/null +++ b/kafka/codec.py @@ -0,0 +1,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 -- cgit v1.2.1