How to use the lz4.frame.compress_update function in lz4

To help you get started, we’ve selected a few lz4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-lz4 / python-lz4 / tests / test_frame.py View on Github external
def test_roundtrip(data, block_size, block_mode,
                   content_checksum, frame_type,
                   compression_level, auto_flush):
    c_context = lz4frame.create_compression_context()
    compressed = lz4frame.compress_begin(
        c_context,
        source_size=len(data),
        compression_level=compression_level,
        block_size=block_size,
        content_checksum=content_checksum,
        frame_type=frame_type,
        auto_flush=auto_flush
    )
    compressed += lz4frame.compress_update(
        c_context,
        data)
    compressed += lz4frame.compress_end(c_context)
    d_context = lz4frame.create_decompression_context()
    decompressed, bytes_read = lz4frame.decompress(d_context, compressed)
    assert bytes_read == len(compressed)
    assert decompressed == data
    del compressed
    del decompressed
    del c_context
    del d_context
github python-lz4 / python-lz4 / tests / test_frame.py View on Github external
data, c_chunks, d_chunks = data_chunked

    c_context = lz4frame.create_compression_context()
    compressed = lz4frame.compress_begin(
        c_context,
        source_size=len(data),
        compression_level=compression_level,
        block_size=block_size,
        content_checksum=content_checksum,
        frame_type=frame_type,
        auto_flush=auto_flush
    )
    data_in = get_chunked(data, c_chunks)
    try:
        while True:
            compressed += lz4frame.compress_update(
                c_context,
                next(data_in)
            )
    except StopIteration:
        pass
    finally:
        del data_in

    compressed += lz4frame.compress_end(c_context)

    d_context = lz4frame.create_decompression_context()
    compressed_in = get_chunked(compressed, d_chunks)
    decompressed = b''
    bytes_read = 0
    try:
        while True:
github python-lz4 / python-lz4 / tests / test_frame.py View on Github external
data, c_chunks, d_chunks = data_chunked

    c_context = lz4frame.create_compression_context()
    compressed = lz4frame.compress_begin(
        c_context,
        source_size=len(data),
        compression_level=compression_level,
        block_size=block_size,
        content_checksum=content_checksum,
        frame_type=frame_type,
        auto_flush=auto_flush
    )
    data_in = get_chunked(data, c_chunks)
    try:
        while True:
            compressed += lz4frame.compress_update(
                c_context,
                next(data_in)
            )
    except StopIteration:
        pass
    finally:
        del data_in

    compressed += lz4frame.compress_end(c_context)

    d_context = lz4frame.create_decompression_context()
    compressed_in = get_chunked(compressed, d_chunks)
    decompressed = b''
    bytes_read = 0
    try:
        while True:
github python-lz4 / python-lz4 / tests / test_frame.py View on Github external
def test_roundtrip(data, block_size, block_mode,
                   content_checksum, frame_type,
                   compression_level, auto_flush):
    c_context = lz4frame.create_compression_context()
    compressed = lz4frame.compress_begin(
        c_context,
        source_size=len(data),
        compression_level=compression_level,
        block_size=block_size,
        content_checksum=content_checksum,
        frame_type=frame_type,
        auto_flush=auto_flush
    )
    compressed += lz4frame.compress_update(
        c_context,
        data)
    compressed += lz4frame.compress_end(c_context)
    d_context = lz4frame.create_decompression_context()
    decompressed, bytes_read = lz4frame.decompress(d_context, compressed)
    assert bytes_read == len(compressed)
    assert decompressed == data
github ooni / pipeline / af / shovel / autoclaving.py View on Github external
file_off = self.__file_off
        ctx = lz4frame.create_compression_context()
        self.__file_write(
            lz4frame.compress_begin(
                ctx,
                block_size=lz4frame.BLOCKSIZE_MAX4MB,  # makes no harm for larger blobs
                block_mode=lz4frame.BLOCKMODE_LINKED,
                compression_level=5,
                content_checksum=lz4frame.CONTENTCHECKSUM_ENABLED,
                # sorry, no per-block checksums yet
                auto_flush=False,
                source_size=self.__frlen,
            )
        )
        for blob, meta in self.__frame:
            self.__file_write(lz4frame.compress_update(ctx, blob))
        self.__file_write(lz4frame.compress_end(ctx))

        json.dump(
            {
                "type": "frame",
                "file_off": file_off,
                "file_size": self.__file_off - file_off,
                "text_off": self.__text_off - self.__frlen,
                "text_size": self.__frlen,
            },
            self.__meta,
            sort_keys=True,
        )
        self.__meta.write("\n")
        for blob, meta in self.__frame:
            if meta is not None: