flush method

String flush()

Flush any remaining buffered bytes.

Call this when the stream ends to get any remaining partial data. This may throw a FormatException if the buffer contains invalid UTF-8.

Implementation

String flush() {
  if (_buffer.isEmpty) return '';

  try {
    final result = utf8.decode(_buffer);
    _buffer.clear();
    return result;
  } catch (e) {
    // Invalid UTF-8 sequence, clear buffer and return empty
    _buffer.clear();
    return '';
  }
}