IOSink class abstract interface

A combined byte and text output.

An IOSink combines a StreamSink of bytes with a StringSink, and allows easy output of both bytes and text.

An IOSink is intended for writing bytes. Strings written through write or writeCharCode will be converted to bytes using encoding. Integer data added using add or addStream will be treated as byte data, and will be truncated to unsigned 8-bit values as by using int.toUnsigned. No guarantees are given for when such a conversion happens, since it depends on the implementation behind the sink.

Writing text (write) and adding bytes (add) may be interleaved freely.

While a stream is being added using addStream, any further attempts to add or write to the IOSink will fail until the addStream completes.

It is an error to add data to the IOSink after the sink is closed.

Implemented types


IOSink(StreamConsumer<List<int>> target, {Encoding encoding = utf8})
Create an IOSink that outputs to a target StreamConsumer of bytes.


done Future
A future that will complete when the consumer closes, or when an error occurs.
no setteroverride
encoding Encoding
The Encoding used when writing strings.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


add(List<int> data) → void
Adds byte data to the target consumer, ignoring encoding.
addError(Object error, [StackTrace? stackTrace]) → void
Passes the error to the target consumer as an error event.
addStream(Stream<List<int>> stream) Future
Adds all elements of the given stream.
close() Future
Close the target consumer.
flush() Future
Returns a Future that completes once all buffered data is accepted by the underlying StreamConsumer.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toString() String
A string representation of this object.
write(Object? object) → void
Converts object to a String by invoking Object.toString and adds the encoding of the result to the target consumer.
writeAll(Iterable objects, [String separator = ""]) → void
Iterates over the given objects and writes them in sequence.
writeCharCode(int charCode) → void
Writes the character of charCode.
writeln([Object? object = ""]) → void
Converts object to a String by invoking Object.toString and writes the result to this, followed by a newline.


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