async fn download_tarball(client: &Client, url: &str, mut dest: File) -> Result<()> {
    use tokio::io::AsyncWriteExt;
    debug!("Downloading tarball: {}", url);
    let mut req = client.get(url);

    req = req.header(header::ACCEPT, "application/octet-stream");
    if let Ok(token) = std::env::var("SHIPCAT_AUTOUPGRADE_TOKEN") {
        req = req.bearer_auth(token);
    }
    let res = req.send().await?;
    let size = res.content_length().unwrap_or(0); // for progress-bar length
    if !res.status().is_success() {
        let status = res.status().to_owned();
        bail!("Failed to download {}: {}", url, status)
    }

    // progress-bar
    let mut downloaded = 0;
    let mut pbar = if size > 0 {
        let pb = ProgressBar::new(size);
        pb.set_style(
            ProgressStyle::default_bar().template("{bar:40.green/black} {bytes}/{total_bytes} ({eta}) {msg}"),
        );
        pb.set_message("downloading");
        Some(pb)
    } else {
        None
    };

    // chunked writing
    let mut stream = res.bytes_stream();
    while let Some(chunk) = stream.try_next().await? {
        dest.write_all(&chunk).await?;
        let n = chunk.len();
        if let Some(ref mut pb) = pbar {
            downloaded = std::cmp::min(downloaded + n as u64, size);
            pb.set_position(downloaded);
        }
    }
    if let Some(ref mut pb) = pbar {
        pb.finish_and_clear();
    }
    Ok(())
}
/// Download the file behind the given `url` into the specified `dest`.
///
/// Presents a progressbar via indicatif when content-length is returned
Download the file behind the given `url` into the specified `dest`.
Presents a progressbar via indicatif when content-length is returned
Download the file behind the given ` url ` into the specified ` dest ` . Presents a progressbar via indicatif when content - length is returned
async fn download_tarball(client: &Client, url: &str, mut dest: File) -> Result<()> {
    use tokio::io::AsyncWriteExt;
    debug!("Downloading tarball: {}", url);
    let mut req = client.get(url);
    req = req.header(header::ACCEPT, "application/octet-stream");
    if let Ok(token) = std::env::var("SHIPCAT_AUTOUPGRADE_TOKEN") {
        req = req.bearer_auth(token);
    }
    let res = req.send().await?;
    let size = res.content_length().unwrap_or(0); // for progress-bar length
    if !res.status().is_success() {
        let status = res.status().to_owned();
        bail!("Failed to download {}: {}", url, status)
    }
    // progress-bar
    let mut downloaded = 0;
    let mut pbar = if size > 0 {
        let pb = ProgressBar::new(size);
        pb.set_style(
            ProgressStyle::default_bar().template("{bar:40.green/black} {bytes}/{total_bytes} ({eta}) {msg}"),
        );
        pb.set_message("downloading");
        Some(pb)
    } else {
        None
    };
    // chunked writing
    let mut stream = res.bytes_stream();
    while let Some(chunk) = stream.try_next().await? {
        dest.write_all(&chunk).await?;
        let n = chunk.len();
        if let Some(ref mut pb) = pbar {
            downloaded = std::cmp::min(downloaded + n as u64, size);
            pb.set_position(downloaded);
        }
    }
    if let Some(ref mut pb) = pbar {
        pb.finish_and_clear();
    }
    Ok(())
}
async fn download_tarball ( client : & Client , url : & str , mut dest : File ) -> Result < ( ) > { use tokio :: io :: AsyncWriteExt ; debug ! ( " " url ) ; let mut req = client . get ( url ) ; req = req . header ( header :: ACCEPT , " " ) ; if let Ok ( token ) = std :: env :: var ( " " ) { req = req . bearer_auth ( token ) ; } let res = req . send ( ) . await ? ; let size = res . content_length ( ) . unwrap_or ( 0 ) ; // for progress-bar length if ! res . status ( ) . is_success ( ) { let status = res . status ( ) . to_owned ( ) ; bail ! ( " " url status ) } // progress-bar let mut downloaded = 0 ; let mut pbar = if size > 0 { let pb = ProgressBar :: new ( size ) ; pb . set_style ( ProgressStyle :: default_bar ( ) . template ( " " ) , ) ; pb . set_message ( " " ) ; Some ( pb ) } else { None } ; // chunked writing let mut stream = res . bytes_stream ( ) ; while let Some ( chunk ) = stream . try_next ( ) . await ? { dest . write_all ( & chunk ) . await ? ; let n = chunk . len ( ) ; if let Some ( ref mut pb ) = pbar { downloaded = std :: cmp :: min ( downloaded + n as u64 , size ) ; pb . set_position ( downloaded ) ; } } if let Some ( ref mut pb ) = pbar { pb . finish_and_clear ( ) ; } Ok ( ( ) ) }
Download the file behind the given `url` into the specified `dest`.
Download the file behind the given ` url ` into the specified ` dest ` .
client
&Client
url
&str
dest
File
client
&Client
url
&str
dest
File