Exemple #1
0
def compress(data):

    compressor = zlib.compressobj()

    for token in map(compressor.compress, map(concatenate_bytes, partition(data, 100))):
        yield token

    yield compressor.flush()
    def generate_bytes(self, data):

        yield WXF_VERSION

        if self.compress:
            yield WXF_HEADER_COMPRESS

        yield WXF_HEADER_SEPARATOR

        if self.compress:
            compressor = zlib.compressobj()
            if six.PY2:
                for payload in self.encode(data):
                    yield compressor.compress(six.binary_type(payload))
            else:
                for payload in self.encode(data):
                    yield compressor.compress(payload)
            yield compressor.flush()
        else:
            for payload in self.encode(data):
                yield payload
Exemple #3
0
 def __init__(self, writer):
     """ Write zip compressed data to a given buffer writer. """
     self._compressor = zlib.compressobj()
     self._writer = writer