decompress method
Implementation
@override
Future<Uint8List?> decompress(Uint8List data) async {
final int compressedSize = data.lengthInBytes;
final Pointer<Uint8> src = malloc.allocate<Uint8>(compressedSize);
src.asTypedList(compressedSize).setAll(0, data);
final int decompressedSizeExpected =
_bindings.ZSTD_getDecompressedSize(src.cast(), compressedSize);
final int dstCapacity = decompressedSizeExpected > 0
? decompressedSizeExpected
: compressedSize * 20;
final Pointer<Uint8> dst = malloc.allocate<Uint8>(dstCapacity);
try {
final int decompressedSize = _bindings.ZSTD_decompress(
dst.cast(),
dstCapacity,
src.cast(),
compressedSize,
);
if (decompressedSize > 0) {
return Uint8List.fromList(dst.asTypedList(decompressedSize));
} else {
return null;
}
} finally {
malloc.free(src);
malloc.free(dst);
}
}