download method

Future<Result<void>> download(
  1. String path,
  2. String savePath, {
  3. Map<String, dynamic>? queryParameters,
  4. Options? options,
  5. CancelToken? cancelToken,
  6. void onReceiveProgress(
    1. int received,
    2. int total
    )?,
})

Downloads the response body for path to savePath.

onReceiveProgress reports (received, total) byte counts; total may be -1 if the server doesn't send Content-Length.

Implementation

Future<Result<void>> download(
  String path,
  String savePath, {
  Map<String, dynamic>? queryParameters,
  Options? options,
  CancelToken? cancelToken,
  void Function(int received, int total)? onReceiveProgress,
}) async {
  try {
    await _dio.download(
      path,
      savePath,
      queryParameters: queryParameters,
      options: options,
      cancelToken: cancelToken,
      onReceiveProgress: onReceiveProgress,
    );
    return const Success<void>(null);
  } on DioException catch (e, st) {
    return Error<void>(mapDioException(e, st));
  } catch (e, st) {
    return Error<void>(
      Failure.unknown(message: e.toString(), cause: e, stackTrace: st),
    );
  }
}