Ejemplo n.º 1
0
 def test_get_block_size(self):
     with self.assertRaises(TypeError):
         get_block_size("1")
     with self.assertRaises(ValueError):
         get_block_size(1)
     self.assertEqual(get_block_size(), get_block_size(LZ4F_BLOCKSIZE_DEFAULT))
     for size in (LZ4F_BLOCKSIZE_MAX64KB, LZ4F_BLOCKSIZE_MAX256KB, LZ4F_BLOCKSIZE_MAX1MB, LZ4F_BLOCKSIZE_MAX4MB):
         self.assertEqual(get_block_size(size), 1 << (8 + (2 * size)))
Ejemplo n.º 2
0
 def test_get_block_size(self):
     with self.assertRaises(TypeError):
         get_block_size('1')
     with self.assertRaises(ValueError):
         get_block_size(1)
     self.assertEqual(get_block_size(),
                      get_block_size(LZ4F_BLOCKSIZE_DEFAULT))
     for size in (LZ4F_BLOCKSIZE_MAX64KB, LZ4F_BLOCKSIZE_MAX256KB,
                  LZ4F_BLOCKSIZE_MAX1MB, LZ4F_BLOCKSIZE_MAX4MB):
         self.assertEqual(get_block_size(size), 1 << (8 + (2 * size)))
Ejemplo n.º 3
0
def compress(file_in, file_out):
    with open(file_in, 'rb') as f1, lzma.open(file_out, 'wb', preset=9) as f2:
        read_size = lz4framed.get_block_size()
        with lz4framed.Compressor(f2) as compressor:
            try:
                while True:
                    compressor.update(f1.read(read_size))
            # empty read result supplied to update()
            except lz4framed.Lz4FramedNoDataError:
                pass
            # input stream exception
            except EOFError:
                pass
Ejemplo n.º 4
0
def do_compress(in_stream, out_stream):
    read = in_stream.read
    read_size = get_block_size()
    try:
        with Compressor(out_stream) as compressor:
            try:
                while True:
                    compressor.update(read(read_size))
            # empty read result supplied to update()
            except Lz4FramedNoDataError:
                pass
            # input stream exception
            except EOFError:
                pass
    except Lz4FramedError as ex:
        __error('Compression error: %s' % ex)
        return 8
    return 0