Function oneio::download_with_retry
source · pub fn download_with_retry(
remote_path: &str,
local_path: &str,
header: Option<HashMap<String, String>>,
retry: usize
) -> Result<(), OneIoError>
Expand description
Downloads a file from a remote path and saves it locally with retry mechanism.
§Arguments
remote_path
- The URL or file path of the file to download.local_path
- The file path to save the downloaded file.header
- Optional headers to include in the download request.retry
- The number of times to retry downloading in case of failure.
§Errors
Returns an Err
variant if downloading fails after all retries, otherwise Ok(())
indicating success.
§Examples
use oneio::download_with_retry;
let remote_path = "https://example.com/file.txt";
let local_path = "/path/to/save/file.txt";
let retry = 3;
match download_with_retry(remote_path, local_path, None, retry) {
Ok(_) => println!("File downloaded successfully"),
Err(e) => eprintln!("Error downloading file: {:?}", e),
}