contentAsString method
Content as plain text.
It will extract the charset parameter from the media type hints to figure out an encoding. Otherwise, fallback on UTF-8.
Implementation
Future<String?> contentAsString() async {
if (!_loadedContentAsString) {
_loadedContentAsString = true;
Encoding encoding = Encoding.getByName(charset ?? Charsets.utf8) ?? utf8;
Stream<List<int>>? _stream = await stream();
_contentAsString =
await _stream?.let((it) async => await encoding.decodeStream(it));
}
return _contentAsString;
}