diff options
author | Joris | 2021-01-03 13:40:40 +0100 |
---|---|---|
committer | Joris | 2021-01-03 13:54:20 +0100 |
commit | 11052951b74b9ad4b6a9412ae490086235f9154b (patch) | |
tree | 64526ac926c1bf470ea113f6cac8a33158684e8d /src/assets.rs | |
parent | 371449b0e312a03162b78797b83dee9d81706669 (diff) |
Rewrite in Rust
Diffstat (limited to 'src/assets.rs')
-rw-r--r-- | src/assets.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/assets.rs b/src/assets.rs new file mode 100644 index 0000000..dc46c78 --- /dev/null +++ b/src/assets.rs @@ -0,0 +1,27 @@ +use sha2::{Digest, Sha256}; +use std::collections::HashMap; +use std::fs; +use std::iter::FromIterator; + +pub fn get() -> HashMap<String, String> { + let paths = fs::read_dir("assets").unwrap().map(|e| { + let path = format!("{}", e.unwrap().path().display()); + let file = fs::read(&path).unwrap(); + let mut path_iter = path.split("/"); + path_iter.next(); + let name = path_iter.collect::<Vec<&str>>().join("/"); + let hashed = format!("/assets/{}/{}", sha256(file), name); + (name, hashed) + }); + HashMap::from_iter(paths) +} + +fn sha256(input: Vec<u8>) -> String { + let mut hasher = Sha256::new(); + hasher.update(input); + hasher + .finalize() + .iter() + .map(|b| format!("{:x}", b)) + .collect() +} |