bodyStream method

Stream<Uint8List> bodyStream()

The body of the request as a stream of bytes.

There is no limit on the size of the body that can be retrieved using this stream, unlike with bodyStr or bodyBytes.

Returns a Stream of Uint8List.

Throws a StateError if bodyStr, bodyBytes or bodyStream has previously been invoked. The stream can only be retrieved once.

Example

Future<void> processBody(Request req) async {
  var total = 0;
  var count = 0;
  await for (final chunk in req.bodyStream()) {
    count++;
    total += chunk.length;
    print('[$count] ${chunk.length} bytes');
    ...
  }
  print('body: $total bytes, received on $count events from bodyStream');
}

Implementation

Stream<Uint8List> bodyStream() => _coreRequest.bodyStream();