diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-23 11:28:17 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-23 11:28:17 +0300 |
commit | 285ddea024ab3204f2032adfa3bb61f7ee238418 (patch) | |
tree | 1900b53feee7e098812c867d973f184e3064658b | |
parent | 1f5d9aed39495980736f25bbd7ec01d5193494c0 (diff) | |
download | summain-rs-285ddea024ab3204f2032adfa3bb61f7ee238418.tar.gz |
spwan blocking task only for checksum update
-rw-r--r-- | src/lib.rs | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -91,20 +91,21 @@ async fn file_checksum(path: PathBuf) -> std::io::Result<String> { let file = File::open(path)?; let mut reader = BufReader::new(file); - let mut buf = vec![0; BUF_SIZE]; loop { + let mut buf = vec![0; BUF_SIZE]; let n = reader.read(&mut buf)?; if n == 0 { break; } - update_checksum(&mut hasher, &buf[..n]); + hasher = tokio::task::spawn_blocking(move || update_checksum(hasher, &buf[..n])).await?; } let hash = hasher.finalize(); Ok(format!("{:x}", hash)) } -fn update_checksum(hasher: &mut Sha256, data: &[u8]) { +fn update_checksum(mut hasher: Sha256, data: &[u8]) -> Sha256 { hasher.update(data); + hasher } mod mode { |