blob method

Future<Blob> blob()

Returns a promise that resolves with a Blob representation of the request body.

MDN reference

Implementation

Future<Blob> blob() async {
  throwIfBodyUsed();

  _storage[#bodyUsed] = true;

  final existing = _storage[#blob];
  if (existing is Blob) return existing;

  final chunks = <Uint8List>[];
  await for (final Uint8List chunk in body ?? Stream.empty()) {
    chunks.add(chunk);
  }

  final blob = Blob(chunks,
      type: headers.get('Content-Type') ?? 'application/octet-stream');

  return _storage[#blob] = blob;
}