// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by General Public License that can be found
// in the LICENSE file.
usesha2::Digest;usestd::fs::File;usestd::io;usestd::io::Read;usestd::path::Path;pubfnsha256sum<P:AsRef<Path>>(file: P)->Result<String, io::Error>{letmut digest =sha2::Sha256::new();letmut reader =File::open(&file)?;letmut buffer =Vec::with_capacity(16*1024);loop{let n_read = reader.read_to_end(&mut buffer)?;if n_read ==0{break;}
digest.update(&buffer[..n_read]);}let result = digest.finalize();Ok(hex::encode(result))}