lz4CompressWithSize function
Uint8List
lz4CompressWithSize(
- Uint8List src, {
- Lz4CompressionLevel level = Lz4CompressionLevel.fast,
- int acceleration = 1,
Compresses src into an LZ4 block with the decompressed size prepended.
The output format is:
- 4 bytes: Little-endian unsigned 32-bit integer representing the length of
src. - N bytes: LZ4 compressed block data.
This allows lz4DecompressWithSize to decompress the block without needing to know the decompressed size beforehand.
level and acceleration behave the same as in lz4Compress.
Implementation
Uint8List lz4CompressWithSize(
Uint8List src, {
Lz4CompressionLevel level = Lz4CompressionLevel.fast,
int acceleration = 1,
}) {
final compressed = lz4Compress(
src,
level: level,
acceleration: acceleration,
);
final out = Uint8List(4 + compressed.length);
final view = ByteData.view(out.buffer);
view.setUint32(0, src.length, Endian.little);
out.setRange(4, out.length, compressed);
return out;
}