pub fn fetch<AnyString0, AnyString1, AnyPath2>(
    url: AnyString0,
    hash: AnyString1,
    path: AnyPath2
) -> Result<(), FetchDataError>where
    AnyString0: AsRef<str>,
    AnyString1: AsRef<str>,
    AnyPath2: AsRef<Path>,
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());