Exemplo n.º 1
0
 def __compress_with_data_and_args(self, data, **kwargs):
     ctx, header = self.__compress_begin(**kwargs)
     in_raw = BytesIO(data)
     out = BytesIO(header)
     out.seek(0, SEEK_END)
     try:
         while True:
             out.write(compress_update(ctx, in_raw.read(1024)))
     except Lz4FramedNoDataError:
         pass
     out.write(compress_end(ctx))
     self.assertEqual(decompress(out.getvalue()), data)
Exemplo n.º 2
0
 def __compress_with_data_and_args(self, data, **kwargs):
     ctx, header = self.__compress_begin(**kwargs)
     in_raw = BytesIO(data)
     out = BytesIO(header)
     out.seek(0, SEEK_END)
     try:
         while True:
             out.write(compress_update(ctx, in_raw.read(1024)))
     except Lz4FramedNoDataError:
         pass
     out.write(compress_end(ctx))
     self.assertEqual(decompress(out.getvalue()), data)
Exemplo n.º 3
0
    def test_compress_end(self):
        with self.assertRaises(TypeError):
            compress_end()
        with self.assertRaises(ValueError):
            compress_end(create_decompression_context())

        ctx, header = self.__compress_begin()
        self.assertEqual(b'', decompress(header + compress_end(ctx)))

        ctx, header = self.__compress_begin()
        data = compress_update(ctx, SHORT_INPUT)
        self.assertEqual(decompress(header + data + compress_end(ctx)),
                         SHORT_INPUT)
Exemplo n.º 4
0
    def test_compress_end(self):
        with self.assertRaises(TypeError):
            compress_end()
        with self.assertRaises(ValueError):
            compress_end(create_decompression_context())

        ctx, header = self.__compress_begin()
        # without any compress_update calls frame is invalid
        with self.assertRaisesLz4FramedError(LZ4F_ERROR_frameHeader_incomplete):
            decompress(header + compress_end(ctx))

        ctx, header = self.__compress_begin()
        data = compress_update(ctx, SHORT_INPUT)
        self.assertEqual(decompress(header + data + compress_end(ctx)), SHORT_INPUT)