summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index b2b65cd..b5c0d93 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,13 @@ struct TagBase {
conn: Connection,
}
+fn hash_file(path: &Path) -> Result<String> {
+ let mut file = std::fs::File::open(path)?;
+ let mut hasher = Blake2b::new();
+ let _ = io::copy(&mut file, &mut hasher)?;
+ Ok(base64::encode(&hasher.result()))
+}
+
impl TagBase {
/// Instantiate a new `TagBase` whose backing database is at `path`.
pub fn new(path: &str) -> Result<Self> {
@@ -72,11 +79,7 @@ impl TagBase {
bail!("`path` does not name a file.");
}
- let mut file = std::fs::File::open(path)?;
- let mut hasher = Blake2b::new();
- let _ = io::copy(&mut file, &mut hasher)?;
- let hash = base64::encode(&hasher.result());
-
+ let hash = hash_file(path)?;
let file_name = path
.file_name()
.and_then(|os| os.to_str())