pub fn fetch<U: AsRef<str>, H: AsRef<str>, P: AsRef<Path>>(
    url: U,
    hash: H,
    path: P
) -> Result<(), FetchDataError>
Expand description

If necessary, retrieve a file from a URL, checking its hash.

Example

use fetch_data::fetch;
use temp_testdir::TempDir;

// Create a temporary local directory.
let temp_dir = TempDir::default();
// Download the file and check its hash.
let path = temp_dir.join("small.fam");
fetch(
    "https://raw.githubusercontent.com/CarlKCarlK/fetch-data/main/tests/data/small.fam",
    "36e0086c0353ff336d0533330dbacb12c75e37dc3cba174313635b98dfe86ed2",
    &path,
)?;
assert!(&path.exists());
// This time, because the local file exists and has the correct hash, no download is performed.
fetch(
    "https://raw.githubusercontent.com/CarlKCarlK/fetch-data/main/tests/data/small.fam",
    "36e0086c0353ff336d0533330dbacb12c75e37dc3cba174313635b98dfe86ed2",
    &path,
)?;
assert!(&path.exists());