Esempio n. 1
0
def test_roundtrip_multiframe_4(data):
    nframes = 4

    compressed = b''
    with lz4frame.LZ4FrameCompressor() as compressor:
        for _ in range(nframes):
            compressed += compressor.begin()
            compressed += compressor.compress(data)
            compressed += compressor.flush()

    decompressed = b''
    with lz4frame.LZ4FrameDecompressor() as decompressor:
        for i in range(nframes):
            if i == 0:
                d = compressed
            else:
                d = decompressor.unused_data
            decompressed += decompressor.decompress(d)
            assert decompressor.eof is True
            assert decompressor.needs_input is True
            if i == nframes - 1:
                assert decompressor.unused_data is None
            else:
                assert len(decompressor.unused_data) == len(compressed) * (
                    nframes - i - 1) / nframes

    assert len(decompressed) == nframes * len(data)
    assert data * nframes == decompressed
Esempio n. 2
0
def test_roundtrip_LZ4FrameCompressor_LZ4FrameDecompressor(
        data,
        chunks,
        block_size,
        block_linked,
        reset,
        store_size,
        block_checksum,
        content_checksum):

    with lz4frame.LZ4FrameCompressor(
            block_size=block_size,
            block_linked=block_linked,
            content_checksum=content_checksum,
            block_checksum=block_checksum,
    ) as compressor:
        def do_compress():
            if store_size is True:
                compressed = compressor.begin(source_size=len(data))
            else:
                compressed = compressor.begin()

            for chunk in get_chunked(data, chunks):
                compressed += compressor.compress(chunk)

            compressed += compressor.flush()
            return compressed

        compressed = do_compress()

        if reset is True:
            compressor.reset()
            compressed = do_compress()

    get_frame_info_check(
        compressed,
        len(data),
        store_size,
        block_size,
        block_linked,
        content_checksum,
        block_checksum,
    )

    with lz4frame.LZ4FrameDecompressor() as decompressor:
        decompressed = b''
        for chunk in get_chunked(compressed, chunks):
            b = decompressor.decompress(chunk)
            decompressed += b

    assert data == decompressed
def lz4decompressor(values):
    values = bytes(values)
    with lz.LZ4FrameDecompressor() as decompressor:
        decompressed = decompressor.decompress(values)
    return list(decompressed)