pub fn download_crs(mut path: std::path::PathBuf) {
    if path.exists() {
        println!("File already exists");
        return;
    }

    // If the path is the path to the 'transcript00.dat' file, pop it off and download the file into the Directory
    if path.ends_with(std::path::Path::new("transcript00.dat")) {
        path.pop();
    }

    let url = "http://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/sealed/transcript00.dat";
    const CHUNK_SIZE: u32 = 10240;

    let client = reqwest::blocking::Client::new();
    let response = client.head(url).send().expect("Expected a response");
    let length = response
        .headers()
        .get(CONTENT_LENGTH)
        .ok_or("response doesn't include the content length")
        .expect("Expected the content length");
    let length = u64::from_str(length.to_str().unwrap())
        .map_err(|_| "invalid Content-Length header")
        .unwrap();

    std::fs::create_dir_all(&path)
        .expect("Failed to create the directory named 'ignition'. Please check your permissions");

    let mut output_file = {
        let fname = "transcript00.dat";

        println!("Downloading the Default SRS (340MB) : Ignite!");
        let fname = path.join(fname);
        println!("\nSRS will be saved at location: '{:?}'", fname);

        File::create(fname).unwrap()
    };

    // XXX: This progress bar redraws on macos after a minute. It's not
    // a problem functionally, however it would be nice to fix.
    let bar = indicatif::ProgressBar::new(length / (CHUNK_SIZE as u64));
    bar.set_style(
        indicatif::ProgressStyle::default_bar()
            .template("[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}")
            .progress_chars("##-"),
    );

    let started = std::time::Instant::now();
    for range in PartialRangeIter::new(0, length - 1, CHUNK_SIZE).unwrap() {
        bar.inc(1);

        let mut response = client.get(url).header(RANGE, range).send().unwrap();

        let status = response.status();
        if !(status == StatusCode::OK || status == StatusCode::PARTIAL_CONTENT) {
            panic!("Unexpected server response: {}", status);
        }
        std::io::copy(&mut response, &mut output_file).unwrap();
    }
    bar.finish();

    println!(
        "Downloading the SRS took {}",
        indicatif::HumanDuration(started.elapsed())
    );

    let content = response.text().unwrap();
    std::io::copy(&mut content.as_bytes(), &mut output_file).unwrap();

    println!("Finished with success!");
}
// XXX: Clean up to handle Errors better and remove the partial file in case we cannot
// download the whole file
Clean up to handle Errors better and remove the partial file in case we cannot
download the whole file
Clean up to handle Errors better and remove the partial file in case we cannot download the whole file
pub fn download_crs(mut path: std::path::PathBuf) {
    if path.exists() {
        println!("File already exists");
        return;
    }
    // If the path is the path to the 'transcript00.dat' file, pop it off and download the file into the Directory
    if path.ends_with(std::path::Path::new("transcript00.dat")) {
        path.pop();
    }
    let url = "http://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/sealed/transcript00.dat";
    const CHUNK_SIZE: u32 = 10240;
    let client = reqwest::blocking::Client::new();
    let response = client.head(url).send().expect("Expected a response");
    let length = response
        .headers()
        .get(CONTENT_LENGTH)
        .ok_or("response doesn't include the content length")
        .expect("Expected the content length");
    let length = u64::from_str(length.to_str().unwrap())
        .map_err(|_| "invalid Content-Length header")
        .unwrap();
    std::fs::create_dir_all(&path)
        .expect("Failed to create the directory named 'ignition'. Please check your permissions");
    let mut output_file = {
        let fname = "transcript00.dat";
        println!("Downloading the Default SRS (340MB) : Ignite!");
        let fname = path.join(fname);
        println!("\nSRS will be saved at location: '{:?}'", fname);
        File::create(fname).unwrap()
    };
    // XXX: This progress bar redraws on macos after a minute. It's not
    // a problem functionally, however it would be nice to fix.
    let bar = indicatif::ProgressBar::new(length / (CHUNK_SIZE as u64));
    bar.set_style(
        indicatif::ProgressStyle::default_bar()
            .template("[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}")
            .progress_chars("##-"),
    );
    let started = std::time::Instant::now();
    for range in PartialRangeIter::new(0, length - 1, CHUNK_SIZE).unwrap() {
        bar.inc(1);
        let mut response = client.get(url).header(RANGE, range).send().unwrap();
        let status = response.status();
        if !(status == StatusCode::OK || status == StatusCode::PARTIAL_CONTENT) {
            panic!("Unexpected server response: {}", status);
        }
        std::io::copy(&mut response, &mut output_file).unwrap();
    }
    bar.finish();
    println!(
        "Downloading the SRS took {}",
        indicatif::HumanDuration(started.elapsed())
    );
    let content = response.text().unwrap();
    std::io::copy(&mut content.as_bytes(), &mut output_file).unwrap();
    println!("Finished with success!");
}
pub fn download_crs ( mut path : std :: path :: PathBuf ) { if path . exists ( ) { println ! ( " " ) ; return ; } // If the path is the path to the 'transcript00.dat' file, pop it off and download the file into the Directory if path . ends_with ( std :: path :: Path :: new ( " " ) ) { path . pop ( ) ; } let url = " " ; const CHUNK_SIZE : u32 = 10240 ; let client = reqwest :: blocking :: Client :: new ( ) ; let response = client . head ( url ) . send ( ) . expect ( " " ) ; let length = response . headers ( ) . get ( CONTENT_LENGTH ) . ok_or ( " " ) . expect ( " " ) ; let length = u64 :: from_str ( length . to_str ( ) . unwrap ( ) ) . map_err ( | _ | " " ) . unwrap ( ) ; std :: fs :: create_dir_all ( & path ) . expect ( " " ) ; let mut output_file = { let fname = " " ; println ! ( " " ) ; let fname = path . join ( fname ) ; println ! ( " \n " fname ) ; File :: create ( fname ) . unwrap ( ) } ; // XXX: This progress bar redraws on macos after a minute. It's not // a problem functionally, however it would be nice to fix. let bar = indicatif :: ProgressBar :: new ( length / ( CHUNK_SIZE as u64 ) ) ; bar . set_style ( indicatif :: ProgressStyle :: default_bar ( ) . template ( " " ) . progress_chars ( " " ) , ) ; let started = std :: time :: Instant :: now ( ) ; for range in PartialRangeIter :: new ( 0 , length - 1 , CHUNK_SIZE ) . unwrap ( ) { bar . inc ( 1 ) ; let mut response = client . get ( url ) . header ( RANGE , range ) . send ( ) . unwrap ( ) ; let status = response . status ( ) ; if ! ( status == StatusCode :: OK || status == StatusCode :: PARTIAL_CONTENT ) { panic ! ( " " status ) ; } std :: io :: copy ( & mut response , & mut output_file ) . unwrap ( ) ; } bar . finish ( ) ; println ! ( " " indicatif HumanDuration ( started elapsed ( ) ) ) ; let content = response . text ( ) . unwrap ( ) ; std :: io :: copy ( & mut content . as_bytes ( ) , & mut output_file ) . unwrap ( ) ; println ! ( " " ) ; }
XXX: Clean up to handle Errors better and remove the partial file in case we cannot
download the whole file
XXX : Clean up to handle Errors better and remove the partial file in case we cannot download the whole file
path
std::path::PathBuf
path
std::path::PathBuf