summaryrefslogtreecommitdiff
path: root/src/chunker/rw/storage.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/chunker/rw/storage.rs')
-rw-r--r--src/chunker/rw/storage.rs41
1 files changed, 6 insertions, 35 deletions
diff --git a/src/chunker/rw/storage.rs b/src/chunker/rw/storage.rs
index 13452d0..135ad4c 100644
--- a/src/chunker/rw/storage.rs
+++ b/src/chunker/rw/storage.rs
@@ -1,4 +1,6 @@
+pub mod bidx;
pub mod build;
+pub mod hash;
pub mod write;
pub use build::build;
@@ -13,52 +15,21 @@ pub struct ChunkInfo {
pub index: usize,
/// Hash of the chunk (hex string)
pub hash: String,
- /// Size of the chunk in bytes
- pub size: usize,
- /// Start position in the original file
- pub start: usize,
- /// End position in the original file (exclusive)
- pub end: usize,
}
-/// 根据hash值计算chunk文件的存储路径
-///
-/// # 参数
-/// - `storage_dir`: 存储目录
-/// - `hash_hex`: chunk的hash值(16进制字符串)
-///
-/// # 返回
-/// 返回chunk文件的完整路径
+/// Calculate the storage path of a chunk file based on its hash value
pub fn get_chunk_path(storage_dir: &Path, hash_hex: &str) -> PathBuf {
let first_slice = &hash_hex[0..2];
- let second_slice = &hash_hex[2..4];
- storage_dir
- .join(first_slice)
- .join(second_slice)
- .join(hash_hex)
+ storage_dir.join(first_slice).join(hash_hex)
}
-/// 根据hash字节数组计算chunk文件的存储路径
-///
-/// # 参数
-/// - `storage_dir`: 存储目录
-/// - `hash_bytes`: chunk的hash值(字节数组)
-///
-/// # 返回
-/// 返回chunk文件的完整路径
+/// Calculate the storage path of a chunk file based on its hash byte array
pub fn get_chunk_path_from_bytes(storage_dir: &Path, hash_bytes: &[u8; 32]) -> PathBuf {
let hash_hex = hex::encode(hash_bytes);
get_chunk_path(storage_dir, &hash_hex)
}
-/// 生成唯一的文件路径,如果文件已存在则添加数字后缀
-///
-/// # 参数
-/// - `output_dir`: 输出目录
-/// - `desired_filename`: 期望的文件名
-///
-/// # 返回
-/// 返回唯一的文件路径
+/// Generate a unique file path, adding a numeric suffix if the file already exists
pub fn generate_unique_path(output_dir: &Path, desired_filename: &str) -> PathBuf {
let desired_path = output_dir.join(desired_filename);
let mut candidate = desired_path.clone();