pub struct ContentDeduplicator { /* private fields */ }Expand description
内容去重器
通过计算文件的SHA256哈希值来识别完全相同的文件, 实现内容级别的去重存储。
Implementations§
Source§impl ContentDeduplicator
impl ContentDeduplicator
Sourcepub fn calculate_hash(data: &[u8]) -> String
pub fn calculate_hash(data: &[u8]) -> String
计算数据的SHA256哈希值
Sourcepub fn check_duplicate(&mut self, hash: &str) -> Option<String>
pub fn check_duplicate(&mut self, hash: &str) -> Option<String>
检查文件是否重复
返回 Some(storage_id) 如果文件已存在,None 如果是新文件
Sourcepub fn register_file(&mut self, hash: String, storage_id: String)
pub fn register_file(&mut self, hash: String, storage_id: String)
注册新文件
当存储新文件时调用,建立哈希值和存储ID的映射
Sourcepub fn remove_reference(&mut self, storage_id: &str) -> bool
pub fn remove_reference(&mut self, storage_id: &str) -> bool
移除文件引用
减少引用计数,如果计数为0则完全移除 返回是否应该删除物理文件
Sourcepub fn remove_hash_reference(&mut self, hash: &str) -> bool
pub fn remove_hash_reference(&mut self, hash: &str) -> bool
通过哈希值移除引用
减少对应存储的引用计数,如果计数为0则完全移除 返回是否应该删除物理文件
Sourcepub fn add_hash_reference(&mut self, hash: &str, storage_id: &str)
pub fn add_hash_reference(&mut self, hash: &str, storage_id: &str)
通过哈希值增加引用
增加对应存储的引用计数
Sourcepub fn get_dedup_info(&self, storage_id: &str) -> Option<DedupInfo>
pub fn get_dedup_info(&self, storage_id: &str) -> Option<DedupInfo>
获取文件的去重信息
Sourcepub fn get_reference_info(&self, hash: &str) -> Option<DedupInfo>
pub fn get_reference_info(&self, hash: &str) -> Option<DedupInfo>
获取引用信息(用于引用文件)
Sourcepub fn get_stats(&self) -> DedupStats
pub fn get_stats(&self) -> DedupStats
获取所有存储的统计信息
Trait Implementations§
Source§impl Debug for ContentDeduplicator
impl Debug for ContentDeduplicator
Auto Trait Implementations§
impl Freeze for ContentDeduplicator
impl RefUnwindSafe for ContentDeduplicator
impl Send for ContentDeduplicator
impl Sync for ContentDeduplicator
impl Unpin for ContentDeduplicator
impl UnwindSafe for ContentDeduplicator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more