decode method
stored, encoded with encoding, decoded to its size bytes.
Throws FormatException for a stream that is not valid or does not
decode to exactly size bytes.
Implementation
Uint8List decode(DVAssetEncoding encoding, Uint8List stored, int size) {
final int codec = _codecFor(encoding);
final ffi.Pointer<ffi.Uint8> input = pkgffi.malloc<ffi.Uint8>(stored.isEmpty ? 1 : stored.length);
final ffi.Pointer<ffi.Uint8> output = pkgffi.malloc<ffi.Uint8>(size == 0 ? 1 : size);
try {
input.asTypedList(stored.length).setAll(0, stored);
final int written = _decode(codec, input, stored.length, output, size);
if (written != size) {
throw FormatException('not a ${encoding.token} stream of $size bytes ($written)');
}
return Uint8List.fromList(output.asTypedList(size));
} finally {
pkgffi.malloc.free(input);
pkgffi.malloc.free(output);
}
}