pub fn hash_file(filename: String) -> FileInfoExpand description
Calculate the hash of a file’s contents.
This function reads the contents of the specified file, calculates its MD5 hash,
and returns the result as a FileInfo struct.
If the file cannot be opened, read, or its contents cannot be decoded as UTF-8,
an error FileInfo with “none” as the hash is returned.
§Arguments
filename- The path to the file for which to calculate the MD5 hash.
§Returns
A FileInfo struct containing the filename and MD5 hash of the file’s contents.
§Examples
use file_integrity::{hash_file, FileInfo};
let filename = "path/to/your/file.txt".to_string();
let file_info = hash_file(filename);
println!("Filename: {}", file_info.filename);
println!("MD5 Hash: {}", file_info.md5_hash);§Errors
This function can return an error if the file cannot be opened, read, or its contents cannot be decoded as UTF-8.