decode method

Future<String> decode(
  1. Encoding encoding, {
  2. int maxBytes = -1,
})

Decodes the body using the given encoding.

Consumes the byte stream and buffers the decoded text in memory. Reading the body again requires a stream that supports replay.

The maxBytes limit counts bytes before decoding. Any negative value, including the default of -1, disables the limit.

Throws a StateError and stops consuming the stream if the body exceeds maxBytes.

Implementation

Future<String> decode(Encoding encoding, {int maxBytes = -1}) =>
    encoding.decodeStream(maxBytes < 0 ? bytes : _limitBytes(bytes, maxBytes));