NullStreamSink<T> class

A StreamSink that discards all events.

The sink silently drops events until close is called, at which point it throws StateErrors when events are added. This is the same behavior as a sink whose remote end has closed, such as when a WebSocket connection has been closed.

This can be used when a sink is needed but no events are actually intended to be added. The NullStreamSink.error constructor can be used to represent errors when creating a sink, since StreamSink.done exposes sink errors. For example:

StreamSink<List<int>> openForWrite(String filename) {
  try {
    return RandomAccessSink(File(filename).openSync());
  } on IOException catch (error, stackTrace) {
    return NullStreamSink.error(error, stackTrace);
  }
}
Implemented types
Available Extensions

Constructors

NullStreamSink({Future? done})
Creates a null sink.
NullStreamSink.error(Object error, [StackTrace? stackTrace])
Creates a null sink whose done future emits error.

Properties

done Future
Return a future which is completed when the StreamSink is finished.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(T data) → void
Adds a data event to the sink.
override
addError(Object error, [StackTrace? stackTrace]) → void
Adds an error to the sink.
override
addStream(Stream<T> stream) Future
Consumes the elements of stream.
override
close() Future
Tells the stream sink that no further streams will be added.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited