debugStream method
Test out the buffer logic by returning randomized, smallish chunks of data at a time. The stream obtained from this method can be fed into another DataInputStream.
Implementation
Stream<Uint8List> debugStream([Random? random]) async* {
random ??= Random();
while (!(await isEOF())) {
var remain = _curr!.length - _pos;
while (remain > 0) {
final len = random.nextInt(remain + 1);
yield Uint8List.view(_curr!.buffer, _curr!.offsetInBytes + _pos, len);
remain -= len;
_pos += len;
}
assert(_pos == _curr!.length);
}
}