fetchStreamed method

Stream<List<int>> fetchStreamed({
  1. CdnFormat? format,
  2. int? size,
})

Fetch this asset and return a stream of its binary data.

Implementation

Stream<List<int>> fetchStreamed({CdnFormat? format, int? size}) async* {
  assert(format != CdnFormat.gif || isAnimated, 'Asset must be animated to fetch as GIF');

  final request = _getRequest(format ?? defaultFormat, size);
  final rawRequest = request.prepare(client);

  final rawResponse = await client.httpHandler.httpClient.send(rawRequest);

  if (rawResponse.statusCode < 200 || rawResponse.statusCode >= 300) {
    throw HttpResponseError.fromResponse(request, rawResponse);
  }

  yield* rawResponse.stream;
}