fn calc_file_hash(path: &str, hash_chunk_size: usize) -> Result<String, ProtocolError> {
    let mut hasher = Blake2s::new(HASH_SIZE);
    let input = File::open(&path).map_err(|err| ProtocolError::StorageError {
        action: format!("open {:?}", path),
        err,
    })?;
    let mut reader = BufReader::with_capacity(hash_chunk_size * 8, input);

    // Need to bring in blake2fs here to create hash
    loop {
        let length = {
            let chunk = reader
                .fill_buf()
                .map_err(|err| ProtocolError::StorageError {
                    action: "read chunk from source".to_owned(),
                    err,
                })?;
            if chunk.is_empty() {
                break;
            }
            hasher.update(&chunk);
            chunk.len()
        };
        reader.consume(length);
        // thread::sleep(Duration::from_millis(2));
    }

    Ok(hasher
        .finalize()
        .as_bytes()
        .iter()
        .map(|val| format!("{:02x}", val))
        .collect::<String>())
}
/// Calculate the blake2s hash for a file at given path
Calculate the blake2s hash for a file at given path
Calculate the blake2s hash for a file at given path
fn calc_file_hash(path: &str, hash_chunk_size: usize) -> Result<String, ProtocolError> {
    let mut hasher = Blake2s::new(HASH_SIZE);
    let input = File::open(&path).map_err(|err| ProtocolError::StorageError {
        action: format!("open {:?}", path),
        err,
    })?;
    let mut reader = BufReader::with_capacity(hash_chunk_size * 8, input);
    // Need to bring in blake2fs here to create hash
    loop {
        let length = {
            let chunk = reader
                .fill_buf()
                .map_err(|err| ProtocolError::StorageError {
                    action: "read chunk from source".to_owned(),
                    err,
                })?;
            if chunk.is_empty() {
                break;
            }
            hasher.update(&chunk);
            chunk.len()
        };
        reader.consume(length);
        // thread::sleep(Duration::from_millis(2));
    }
    Ok(hasher
        .finalize()
        .as_bytes()
        .iter()
        .map(|val| format!("{:02x}", val))
        .collect::<String>())
}
fn calc_file_hash ( path : & str , hash_chunk_size : usize ) -> Result < String , ProtocolError > { let mut hasher = Blake2s :: new ( HASH_SIZE ) ; let input = File :: open ( & path ) . map_err ( | err | ProtocolError :: StorageError { action : format ! ( " " path ) , err , } ) ? ; let mut reader = BufReader :: with_capacity ( hash_chunk_size * 8 , input ) ; // Need to bring in blake2fs here to create hash loop { let length = { let chunk = reader . fill_buf ( ) . map_err ( | err | ProtocolError :: StorageError { action : " " . to_owned ( ) , err , } ) ? ; if chunk . is_empty ( ) { break ; } hasher . update ( & chunk ) ; chunk . len ( ) } ; reader . consume ( length ) ; // thread::sleep(Duration::from_millis(2)); } Ok ( hasher . finalize ( ) . as_bytes ( ) . iter ( ) . map ( | val | format ! ( " " val ) ) . collect :: < String > ( ) ) }
Calculate the blake2s hash for a file at given path
Calculate the blake2s hash for a file at given path
path
&str
hash_chunk_size
usize
path
&str
hash_chunk_size
usize