readStored method

Uint8List readStored(
  1. DVPackedAsset asset, {
  2. int start = 0,
  3. int? end,
})

asset's bytes as they are stored, or the part of them from start to end: what a client that accepts DVPackedAsset.encoding is sent.

A positioned read of exactly that range. Synchronous, and so never interleaved with another read of the same file by this isolate.

Implementation

Uint8List readStored(DVPackedAsset asset, {int start = 0, int? end}) {
  final int stop = RangeError.checkValidRange(start, end, asset.storedLength);
  if (stop == start) return Uint8List(0);
  final RandomAccessFile file = _open ??= File(_file).openSync();
  file.setPositionSync(asset._offset + start);
  final Uint8List bytes = file.readSync(stop - start);
  if (bytes.length != stop - start) {
    throw FileSystemException(
        'the executable ended inside ${asset.path}', _file);
  }
  return bytes;
}