read method
Reads exactly the bytes covered by range.
Implementation
@override
Future<Uint8List> read(ByteRange range) => _synchronized(() async {
final available = ByteRange(0, _snapshotLength);
if (!available.containsRange(range)) {
throw ByteRangeOutOfBoundsException(range, available);
}
await _verifyLength();
try {
await _handle.setPosition(range.start);
final bytes = await _handle.read(range.length);
if (bytes.length != range.length) {
throw TruncatedReadException(
range: range,
expectedLength: range.length,
actualLength: bytes.length,
);
}
await _verifyLength();
return Uint8List.fromList(bytes);
} on ByteIoException {
rethrow;
} on FileSystemException catch (error) {
throw ByteSourceIoException(
operation: 'read bytes',
cause: error,
location: _file.path,
);
}
});