Skip to content

Instantly share code, notes, and snippets.

@PlugFox
Created April 22, 2025 10:24
Show Gist options
  • Save PlugFox/c82c6147ccac451faa55efa8b55c80ae to your computer and use it in GitHub Desktop.
Save PlugFox/c82c6147ccac451faa55efa8b55c80ae to your computer and use it in GitHub Desktop.
Dart Utf8Decoder example
/*
* Dart Utf8Decoder example
* https://gist.github.com/PlugFox/c82c6147ccac451faa55efa8b55c80ae
* https://dartpad.dev?id=c82c6147ccac451faa55efa8b55c80ae
* Mike Matiunin <[email protected]>, 22 April 2025
*/
// ignore_for_file: avoid_print
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
void main() {
final bytes = Uint8List.fromList([65, 66, 67, 49, 50, 51]);
final stream = Stream.value(bytes); // Stream<List<int>>.value(bytes)
stream.transform<String>(const Utf8Decoder(allowMalformed: true)).forEach(print);
print(const Utf8Decoder(allowMalformed: true).convert(bytes));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment