fn download_a_chunk(http_client: &Client,
                    http_header: Headers,
                    mut chunk_writer: OutputChunkWriter,
                    url: &str,
                    mpb: &mut ProgressBar<Pipe>)
                    -> Result<Bytes, Error> {

    let mut body = http_client.get_http_response_using_headers(url, http_header).unwrap();
    if !body.check_partialcontent_status() {
        return Err(Error::Status);
    }
    let mut bytes_buffer = [0; DOWNLOAD_BUFFER_BYTES];
    let mut sum_bytes = 0;

    let progress_update_interval = Duration::from_millis(PROGRESS_UPDATE_INTERVAL_MILLIS);
    let mut last_progress_bytes = 0;
    let mut last_progress_time = Instant::now() - progress_update_interval;

    while let Ok(n) = body.read(&mut bytes_buffer) {
        if n == 0 {
            return Ok(sum_bytes);
        }

        chunk_writer.write(sum_bytes, &bytes_buffer[0..n]);

        sum_bytes += n as u64;

        // Update the CLI
        if Instant::now().duration_since(last_progress_time) > progress_update_interval {
            last_progress_time = Instant::now();
            let progress_bytes_delta = sum_bytes - last_progress_bytes;
            last_progress_bytes = sum_bytes;
            mpb.add(progress_bytes_delta);
        }
    }
    mpb.add(sum_bytes - last_progress_bytes);
    return Ok(0u64);
}
/// Function to get from the server the content of a chunk.
/// This function returns a Result type - Bytes if the content of the header is accessible, an Error type otherwise.
Function to get from the server the content of a chunk.
This function returns a Result type - Bytes if the content of the header is accessible, an Error type otherwise.
Function to get from the server the content of a chunk . This function returns a Result type - Bytes if the content of the header is accessible an Error type otherwise .
fn download_a_chunk(http_client: &Client,
                    http_header: Headers,
                    mut chunk_writer: OutputChunkWriter,
                    url: &str,
                    mpb: &mut ProgressBar<Pipe>)
                    -> Result<Bytes, Error> {
    let mut body = http_client.get_http_response_using_headers(url, http_header).unwrap();
    if !body.check_partialcontent_status() {
        return Err(Error::Status);
    }
    let mut bytes_buffer = [0; DOWNLOAD_BUFFER_BYTES];
    let mut sum_bytes = 0;
    let progress_update_interval = Duration::from_millis(PROGRESS_UPDATE_INTERVAL_MILLIS);
    let mut last_progress_bytes = 0;
    let mut last_progress_time = Instant::now() - progress_update_interval;
    while let Ok(n) = body.read(&mut bytes_buffer) {
        if n == 0 {
            return Ok(sum_bytes);
        }
        chunk_writer.write(sum_bytes, &bytes_buffer[0..n]);
        sum_bytes += n as u64;
        // Update the CLI
        if Instant::now().duration_since(last_progress_time) > progress_update_interval {
            last_progress_time = Instant::now();
            let progress_bytes_delta = sum_bytes - last_progress_bytes;
            last_progress_bytes = sum_bytes;
            mpb.add(progress_bytes_delta);
        }
    }
    mpb.add(sum_bytes - last_progress_bytes);
    return Ok(0u64);
}
fn download_a_chunk ( http_client : & Client , http_header : Headers , mut chunk_writer : OutputChunkWriter , url : & str , mpb : & mut ProgressBar < Pipe > ) -> Result < Bytes , Error > { let mut body = http_client . get_http_response_using_headers ( url , http_header ) . unwrap ( ) ; if ! body . check_partialcontent_status ( ) { return Err ( Error :: Status ) ; } let mut bytes_buffer = [ 0 ; DOWNLOAD_BUFFER_BYTES ] ; let mut sum_bytes = 0 ; let progress_update_interval = Duration :: from_millis ( PROGRESS_UPDATE_INTERVAL_MILLIS ) ; let mut last_progress_bytes = 0 ; let mut last_progress_time = Instant :: now ( ) - progress_update_interval ; while let Ok ( n ) = body . read ( & mut bytes_buffer ) { if n == 0 { return Ok ( sum_bytes ) ; } chunk_writer . write ( sum_bytes , & bytes_buffer [ 0 .. n ] ) ; sum_bytes += n as u64 ; // Update the CLI if Instant :: now ( ) . duration_since ( last_progress_time ) > progress_update_interval { last_progress_time = Instant :: now ( ) ; let progress_bytes_delta = sum_bytes - last_progress_bytes ; last_progress_bytes = sum_bytes ; mpb . add ( progress_bytes_delta ) ; } } mpb . add ( sum_bytes - last_progress_bytes ) ; return Ok ( 0u64 ) ; }
Function to get from the server the content of a chunk.
Function to get from the server the content of a chunk .
http_client
&Client
http_header
Headers
chunk_writer
OutputChunkWriter
url
&str
mpb
&mut ProgressBar<Pipe>
http_client
&Client
http_header
Headers
chunk_writer
OutputChunkWriter
url
&str
mpb
&mut ProgressBar<Pipe>