readAsString method

Future<ResourceTry<String>> readAsString({
  1. String? charset,
})

Reads the full content as a String.

If charset is null, then it is parsed from the charset parameter of link().type, or falls back on UTF-8.

Implementation

Future<ResourceTry<String>> readAsString({String? charset}) async {
  charset = charset ?? (await link()).mediaType.charset ?? Charsets.utf8;
  return read().then((st) => st.mapCatching((data) {
        Encoding encoding = Encoding.getByName(charset) ?? utf8;
        return encoding.decoder.convert(data.buffer.asUint8List());
      }));
}