pub fn hash_file<P: AsRef<Path>>(path: P) -> Result<String, FetchDataError>
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"));