ConsolePrintStream constructor
ConsolePrintStream([
- IOSink? sink
A concrete implementation of PrintStream that writes to the console using stdout.
ConsolePrintStream
provides a high-level abstraction over stdout
,
offering utility methods like write
, writeln
, newline
, flush
, and close
.
By default, it uses stdout.nonBlocking
for efficient, non-blocking output,
but you can also provide a custom IOSink to redirect output (e.g., to a file).
📦 Example Usage:
final stream = ConsolePrintStream();
stream.write('Hello');
stream.writeln(' world');
stream.newline();
stream.flush();
await stream.close();
This class is useful when abstracting over console or file output in logging systems, REPLs, shell interfaces, and testable I/O components.
Creates a ConsolePrintStream that writes to stdout by default.
You may optionally provide a custom sink
(e.g., file or socket).
Implementation
ConsolePrintStream([IOSink? sink]) : _sink = sink ?? stdout.nonBlocking;