read method

  1. @override
Future<Uint8List> read([
  1. int? length
])
override

Reads data from the connection. If length is provided, reads exactly that many bytes. Otherwise, reads whatever is available.

Implementation

@override
Future<Uint8List> read([int? length]) async {
  if (_closed) {
    throw Exception('Connection is closed');
  }

  try {
    final data = await _stream.read();
    if (data == null) {
      throw Exception('unexpected EOF');
    }

    if (length != null && data.length < length) {
      throw Exception('not enough data');
    }

    _manager.recordActivity(this);
    return data;
  } catch (e) {
    _handleError(e);
    rethrow;
  }
}