read method

Future<List<T>> read(
  1. int size
)

Read fully size bytes from the stream and return in the future.

Throws ArgumentError if size is larger than optional buffer limit.

Implementation

Future<List<T>> read(int size) {
  if (limited && size > limit) {
    throw ArgumentError('Cannot read $size with limit $limit');
  }

  // If we have enough data to consume and there are no other readers, then
  // we can return immediately.
  if (size <= buffered && _readers.isEmpty) {
    return Future<List<T>>.value(_consume(size));
  }
  final completer = Completer<List<T>>();
  _readers.add(_ReaderInWaiting<List<T>>(size, completer));
  return completer.future;
}