readBytes static method

Future<Uint8List?> readBytes(
  1. Uri url, {
  2. Map<String, String>? headers,
  3. CancellationToken? cancelToken,
  4. int retries = 3,
  5. Duration? timeLimit,
  6. Duration timeRetry = const Duration(milliseconds: 100),
  7. FutureOr<Uint8List> onTimeout()?,
})

Implementation

static Future<Uint8List?> readBytes(Uri url,
    {Map<String, String>? headers,
    CancellationToken? cancelToken,
    int retries = 3,
    Duration? timeLimit,
    Duration timeRetry = const Duration(milliseconds: 100),
    FutureOr<Uint8List> Function()? onTimeout}) async {
  cancelToken?.throwIfCancellationRequested();
  return await RetryHelper.tryRun<Uint8List>(
    () {
      return CancellationTokenSource.register(
        cancelToken,
        timeLimit == null
            ? _httpClient.readBytes(
                url,
                headers: headers,
              )
            : _httpClient
                .readBytes(
                  url,
                  headers: headers,
                )
                .timeout(
                  timeLimit,
                  onTimeout: onTimeout,
                ),
      );
    },
    cancelToken: cancelToken,
    timeRetry: timeRetry,
    retries: retries,
  );
}