read method
Exactly length bytes at offset, or a thrown error.
Returning a short read silently is the one behaviour that breaks every caller, so implementations must not do it.
Implementation
@override
Future<Uint8List> read(int offset, int length) async {
if (offset < 0 || length < 0 || offset + length > _size) {
throw RangeError(
'4dgs: range [$offset, ${offset + length}) outside $_size bytes',
);
}
await _handle.setPosition(offset);
final out = await _handle.read(length);
// A short read is the one behaviour that breaks every caller, and a file can
// produce one — it may have been truncated between the size call and this
// read. Reported rather than returned.
if (out.length != length) {
throw FourdgsTruncatedFile(
'read $length bytes at $offset and got ${out.length}',
);
}
return out;
}