readAt method
Reads into dst[start..end) at offset. Returns bytes read (0 at EOF).
Implementation
@override
Future<int> readAt(
int offset,
Uint8List dst, {
int start = 0,
int? end,
}) async {
final e = end ?? dst.length;
RangeError.checkValidRange(start, e, dst.length);
if (offset < 0) throw RangeError.value(offset, 'offset');
if (e == start) return 0;
_checkOpen();
return _serialize(() async {
if (offset >= _length) return 0;
final want = math.min(e - start, _length - offset);
if (want <= 0) return 0;
final first = offset ~/ chunkSize;
final last = (offset + want - 1) ~/ chunkSize;
await _loadChunks([
for (var i = first; i <= last; i++) i,
], readOnly: true);
var done = 0;
while (done < want) {
final absolute = offset + done;
final index = absolute ~/ chunkSize;
final inChunk = absolute % chunkSize;
final take = math.min(want - done, chunkSize - inChunk);
final cached = _cache[index];
if (cached == null) {
dst.fillRange(start + done, start + done + take, 0);
} else {
dst.setRange(start + done, start + done + take, cached, inChunk);
}
done += take;
}
return done;
});
}