decompress function
Throw ZStdError if failed.
Implementation
Uint8List decompress(Uint8List src) {
_lib ??= ZStd(_openLibrary());
final csrc = Uint8ArrayUtils.toPointer(src);
final dstlen = _lib!.ZSTD_getDecompressedSize(csrc.cast(), src.length);
final dst = calloc<ffi.Uint8>(dstlen);
try {
int reslen =
_lib!.ZSTD_decompress(dst.cast(), dstlen, csrc.cast(), src.length);
if (_lib!.ZSTD_isError(reslen) > 0) {
throw ZStdError.fromCode(reslen);
}
return Uint8ArrayUtils.fromPointer(dst, reslen);
} finally {
calloc.free(dst);
calloc.free(csrc);
}
}