read method

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

Reads data from the stream

Implementation

@override
Future<Uint8List> read([int? maxLength]) async {
  if (_isClosed) {
    throw ResetException('Stream is closed');
  }
  try {
    // MuxedStream.read expects a length. If maxLength is null, decide a default.
    // If maxLength is 0, it might mean read whatever is available for some muxers.
    // This needs to align with the specific MuxedStream implementation.
    final data = await _underlyingMuxedStream.read(maxLength ?? 0); // Assuming 0 means read available for underlying
    return Uint8List.fromList(data);
  } on ResetException {
    await _handleResetOrClose();
    rethrow;
  } catch (e) {
    await _handleResetOrClose();
    throw ResetException('Read error: $e');
  }
}