Utf8StreamDecoder class

A UTF-8 stream decoder that handles incomplete byte sequences gracefully.

This decoder buffers incomplete UTF-8 byte sequences and only emits complete, valid UTF-8 strings. This prevents FormatException when multi-byte characters are split across network chunks.

Example usage:

final decoder = Utf8StreamDecoder();

await for (final chunk in byteStream) {
  final decoded = decoder.decode(chunk);
  if (decoded.isNotEmpty) {
    print(decoded);
  }
}

// Don't forget to flush any remaining bytes
final remaining = decoder.flush();
if (remaining.isNotEmpty) {
  print(remaining);
}

Constructors

Utf8StreamDecoder.new()

Properties

bufferedByteCount int
Get the number of buffered bytes.
no setter
hasBufferedBytes bool
Check if there are buffered bytes waiting for completion.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decode(List<int> chunk) String
Decode a chunk of bytes, returning only complete UTF-8 strings.
flush() String
Flush any remaining buffered bytes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Clear the internal buffer.
toString() String
A string representation of this object.
inherited

Operators

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