readAhead method Null safety

Future readAhead(
  1. int length
)

Completes when minimum length amount of bytes are in the buffer.

Implementation

Future readAhead(int length) {
  if (remainingLength >= length) {
    return Future.value();
  }
  if (_readAheadCompleter != null && _readAheadRequired == length) {
    return _readAheadCompleter!.future;
  }
  if (_readAheadCompleter != null && _readAheadRequired != length) {
    throw StateError('A different readAhead is already waiting.');
  }
  _readAheadRequired = length;
  _readAheadCompleter = Completer();
  return _readAheadCompleter!.future;
}