Exemplo 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
Exemplo n.º 2
0
 def test_LZ4FrameCompressor(self):
     input_data = b"2099023098234882923049823094823094898239230982349081231290381209380981203981209381238901283098908123109238098123"
     with lz4frame.LZ4FrameCompressor() as compressor:
         compressed = compressor.compress(input_data)
         compressed += compressor.flush()
     decompressed = lz4frame.decompress(compressed)
     self.assertEqual(input_data, decompressed)
Exemplo n.º 3
0
 def test_LZ4FrameCompressor_fails(self):
     input_data = b"2099023098234882923049823094823094898239230982349081231290381209380981203981209381238901283098908123109238098123"
     with self.assertRaisesRegexp(RuntimeError,
                                  r'compress called after flush'):
         with lz4frame.LZ4FrameCompressor() as compressor:
             compressed = compressor.compress(input_data)
             compressed += compressor.flush()
             compressed = compressor.compress(input_data)
Exemplo n.º 4
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 lz4compressor(values):
    with lz.LZ4FrameCompressor() as compressor:
        compressed = compressor.begin()
        compressed += compressor.compress(bytes(values))
        compressed += compressor.flush()
    return list(compressed)