String asString()

Returns decoded data as String if decoding as already occurred.

If decoding has not yet occurred, this method throws an HTTPBodyDecoderException.

If decoding as occurred, behavior is the same as decodeAsString, but the result is not wrapped in Future.

Source

String asString() {
  if (!hasBeenDecoded) {
    throw new HTTPBodyDecoderException("asString() invoked, but has not been decoded yet.");
  }

  if (_decodedData == null) {
    return null;
  }

  var d = _decodedData as List<String>;
  return d.fold(new StringBuffer(), (StringBuffer buf, value) {
    if (value is! String) {
      throw new HTTPBodyDecoderException("asString() failed: non-String data emitted from codec");
    }

    buf.write(value);
    return buf;
  }).toString();
}