flush abstract method
Flushes this stream by writing any buffered output to the underlying stream.
If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
Implementation Note
Implementations should ensure that all buffered data is written to the underlying stream. If the underlying stream is also Flushable, it should be flushed as well to ensure data reaches its final destination.
Example
@override
Future<void> flush() async {
// Write buffered data to underlying stream
if (_buffer.isNotEmpty) {
await _underlyingStream.write(_buffer);
_buffer.clear();
}
// Flush underlying stream if it's also flushable
if (_underlyingStream is Flushable) {
await (_underlyingStream as Flushable).flush();
}
}
Throws IOException if an I/O error occurs during flushing.
Implementation
Future<void> flush();