refactor check logic.

This commit is contained in:
2025-11-21 00:52:15 +08:00
parent bd0c755370
commit 852384a9fc
7 changed files with 166 additions and 73 deletions
+16 -9
View File
@@ -111,13 +111,20 @@ impl FileMeta {
pub fn to_pretty_json(&self) -> Result<String> {
Ok(serde_json::to_string_pretty(self)?)
}
pub fn matches(&self, other: &Self) -> bool {
self.size == other.size
&& self.ed2k == other.ed2k
&& self.md5 == other.md5
&& self.sha1 == other.sha1
&& self.sha256 == other.sha256
&& self.xxh128 == other.xxh128
}
}
pub fn calc_xxh128(path: &Path) -> Result<String> {
let mut file = File::open(path).with_context(|| format!("无法打开文件: {}", path.display()))?;
let mut buffer = vec![0u8; DEFAULT_BUFFER_SIZE];
let mut hasher = Xxh3::new();
loop {
let read_len = file.read(&mut buffer)?;
if read_len == 0 {
break;
}
hasher.update(&buffer[..read_len]);
}
Ok(hex_upper(hasher.digest128().to_be_bytes()))
}