readBytes method
Reads and buffers the body, up to maxBytes.
Implementation
Future<Uint8List> readBytes({int maxBytes = 10 * 1024 * 1024}) async {
final builder = BytesBuilder(copy: false);
var length = 0;
await for (final chunk in body) {
length += chunk.length;
if (length > maxBytes) {
throw PayloadTooLargeException(maxBytes);
}
builder.add(chunk);
}
return builder.takeBytes();
}