read method
Reads an owned or immutable range without changing the source.
Implementation
@override
Uint8List read(int offset, int count) {
if (_closed) {
throw StateError('XCF input is closed');
}
if (offset < 0 || count < 0 || count > length - offset) {
throw RangeError('XCF input range is outside the file');
}
if (offset >= _start && offset + count <= _start + _cache.length) {
return Uint8List.sublistView(_cache, offset - _start, offset - _start + count);
}
_file.setPositionSync(offset);
final int size = (count > cacheBytes ? count : cacheBytes).clamp(0, length - offset);
final Uint8List bytes = _file.readSync(size);
if (bytes.length != size) {
throw const XcfFormatException('File changed or was truncated during XCF reading');
}
if (size <= cacheBytes) {
_start = offset;
_cache = bytes;
}
return Uint8List.sublistView(bytes, 0, count);
}