Flushable constructor

Flushable()

An object that can be flushed.

The flush method is invoked to write any buffered output to the underlying stream or device. This is particularly important for buffered streams where data may be held in memory until the buffer is full or explicitly flushed.

Example Usage

class BufferedOutput implements Flushable {
  final List<int> _buffer = [];
  final OutputStream _output;
  
  BufferedOutput(this._output);
  
  void write(int byte) {
    _buffer.add(byte);
    if (_buffer.length >= 1024) {
      flush(); // Auto-flush when buffer is full
    }
  }
  
  @override
  Future<void> flush() async {
    if (_buffer.isNotEmpty) {
      await _output.write(_buffer);
      _buffer.clear();
    }
  }
}

Implementation

Flushable();