readBinaryFile method

Future<Uint8List> readBinaryFile(
  1. String fileName, {
  2. String? package,
})

Reads a binary file from the assets.

The fileName is the full path of the asset. When a package is given, the path is resolved relative to that package's assets.

Implementation

Future<Uint8List> readBinaryFile(String fileName, {String? package}) async {
  final path = _resolve(fileName, package);
  if (!_files.containsKey(path)) {
    _files[path] = await _readBinary(path);
  }
  assert(
    _files[path] is _BinaryAsset,
    '"$path" was previously loaded as a text file',
  );
  return (_files[path]! as _BinaryAsset).value;
}