Function hash_file

Source
pub fn hash_file<AnyPath0>(
    path: AnyPath0,
) -> Result<String, Box<FetchDataError>>
where AnyPath0: AsRef<Path>,
Expand description

Compute the hash (SHA256) of a local file.

ยงExample

use fetch_data::{hash_file, download};
use temp_testdir::TempDir;

// Download a file to a temporary directory.
let temp_dir = TempDir::default();
let path = temp_dir.join("small.fam");
download(
    "https://raw.githubusercontent.com/CarlKCarlK/fetch-data/main/tests/data/small.fam",
    &path,
)?;
// Compute the hash of the file.
let hash = hash_file(&path)?;
assert!(hash.eq("36e0086c0353ff336d0533330dbacb12c75e37dc3cba174313635b98dfe86ed2"));