takeBodyStream method

Stream<List<int>> takeBodyStream()

Returns the underlying body stream, marking it as consumed.

Throws StateError if this response is buffered (isStreaming is false), or if takeBodyStream has already been called on this instance.

Implementation

Stream<List<int>> takeBodyStream() {
  final stream = _bodyStream;
  if (stream == null) {
    throw StateError(
      'BloomResponse.takeBodyStream() called on a buffered response. '
      'Check isStreaming before calling.',
    );
  }
  if (_streamTaken) {
    throw StateError(
      'BloomResponse body stream has already been taken. A response body '
      'may only be consumed once.',
    );
  }
  _streamTaken = true;
  return stream;
}