def deflate(data): c = zlib.compressobj() out = c.compress(data) out += c.flush(zlib.Z_SYNC_FLUSH) return out