decodeUtf8Stream method
Transform a byte stream into a UTF-8 string stream with proper handling of incomplete multi-byte sequences.
Implementation
Stream<String> decodeUtf8Stream() async* {
final decoder = Utf8StreamDecoder();
await for (final chunk in this) {
final decoded = decoder.decode(chunk);
if (decoded.isNotEmpty) {
yield decoded;
}
}
// Flush any remaining bytes
final remaining = decoder.flush();
if (remaining.isNotEmpty) {
yield remaining;
}
}