| Crates.io | stowr-core |
| lib.rs | stowr-core |
| version | 0.3.0 |
| created_at | 2025-06-24 14:20:14.707324+00 |
| updated_at | 2025-06-26 06:25:33.904889+00 |
| description | Core library for stowr file management system - provides file compression, storage, and indexing functionality |
| homepage | https://github.com/XiaoLinXiaoZhu/stowr-core |
| repository | https://github.com/XiaoLinXiaoZhu/stowr-core |
| max_upload_size | |
| id | 1724368 |
| size | 138,690 |
stowr-core 是一个用 Rust 编写的文件管理核心库,提供文件压缩、存储和索引功能。它可以独立使用,也可以集成到其他应用程序中。
STOWR是一个由“Store”和“Owe”,两个单词组合而成的名称。它能够实现动态的 压缩/解压 文件功能,实现小文件的优化存储。
当文件被存储时,它对于 STOWR 来说处于“Store”状态;而对于文件读写来说,它处于“Owe”状态。当文件被解压后,它将被从STOWR中删除,STOWR将不再拥有该文件。
当处于“Owe”状态时,文件的内容是不可见的,但是你仍然可以将其重命名、移动或删除。
想要查看文件内容,你需要首先使用 STOWR 将其提取出来,提取之后,stowr 将不再 “store” 该文件,“owe"关系也会被解除。
想想看:stowr owe me_a_file.txt stowr 你欠我一个文件!
将以下依赖添加到您的 Cargo.toml:
[dependencies]
stowr-core = "0.2.2"
use stowr_core::{Config, StorageManager, create_index};
use std::path::Path;
fn main() -> anyhow::Result<()> {
// 创建配置
let config = Config::default();
// 创建索引
let index = create_index(&config)?;
// 创建存储管理器
let mut storage = StorageManager::new(config, index);
// 存储文件
storage.store_file(Path::new("example.txt"), false)?;
// 列出所有文件
let files = storage.list_files()?;
for file in files {
println!("File: {} ({} bytes)",
file.original_path.display(),
file.file_size);
}
// 搜索文件
let results = storage.search_files("*.txt")?;
println!("Found {} text files", results.len());
// 提取文件
storage.owe_file(Path::new("example.txt"))?;
Ok(())
}
use stowr_core::{Config, IndexMode, CompressionAlgorithm, DeltaAlgorithm};
use std::path::PathBuf;
let mut config = Config::default();
config.storage_path = PathBuf::from("./my_storage");
config.index_mode = IndexMode::Sqlite; // 强制使用 SQLite 索引
config.compression_algorithm = CompressionAlgorithm::Zstd; // 使用 zstd 压缩
config.compression_level = 15; // zstd 高压缩级别
config.multithread = 4; // 使用 4 个线程
// 去重和差分配置
config.enable_deduplication = true; // 启用内容去重
config.enable_delta_compression = true; // 启用差分压缩
config.similarity_threshold = 0.8; // 80% 相似度阈值
config.delta_algorithm = DeltaAlgorithm::Simple; // 差分算法
STOWR 提供强大的去重和差分存储功能,特别适合存储大量相似文件:
use stowr_core::{Config, StorageManager, create_index, DeltaAlgorithm};
// 配置去重和差分功能
let mut config = Config::default();
config.enable_deduplication = true; // 启用内容去重
config.enable_delta_compression = true; // 启用差分压缩
config.similarity_threshold = 0.7; // 70% 相似度阈值
let index = create_index(&config)?;
let mut storage = StorageManager::new(config, index);
// 存储文件 - 自动检测重复和相似文件
storage.store_file(Path::new("texture_v1.png"), false)?;
storage.store_file(Path::new("texture_v2.png"), false)?; // 可能被差分存储
storage.store_file(Path::new("texture_v1_copy.png"), false)?; // 可能被去重
不同的压缩算法适用于不同的场景:
use stowr_core::{Config, CompressionAlgorithm};
// 使用不同的压缩算法
let mut config = Config::default();
// 高压缩率场景
config.compression_algorithm = CompressionAlgorithm::Zstd;
config.compression_level = 20;
// 高速度场景
config.compression_algorithm = CompressionAlgorithm::Lz4;
// lz4 无需设置压缩级别
// 兼容性场景
config.compression_algorithm = CompressionAlgorithm::Gzip;
config.compression_level = 6;
// 从文件列表批量存储
storage.store_files_from_list(Path::new("file_list.txt"), false)?;
// 批量提取
storage.owe_files_from_list(Path::new("extract_list.txt"))?;
// 提取所有文件
storage.owe_all_files()?;
// 重命名文件
storage.rename_file(Path::new("old_name.txt"), Path::new("new_name.txt"))?;
// 移动文件
storage.move_file(Path::new("file.txt"), Path::new("new/location/"))?;
// 删除文件
storage.delete_file(Path::new("unwanted.txt"))?;
use stowr_core::{Config, StorageManager, create_index};
use tauri::State;
use std::sync::Mutex;
type StorageState = Mutex<StorageManager>;
#[tauri::command]
async fn store_file(
state: State<'_, StorageState>,
file_path: String,
) -> Result<String, String> {
let mut storage = state.lock().unwrap();
storage.store_file(Path::new(&file_path), false)
.map_err(|e| e.to_string())?;
Ok("File stored successfully".to_string())
}
use stowr_core::{Config, StorageManager, create_index};
pub struct FileService {
storage: StorageManager,
}
impl FileService {
pub fn new() -> anyhow::Result<Self> {
let config = Config::default();
let index = create_index(&config)?;
let storage = StorageManager::new(config, index);
Ok(Self { storage })
}
pub fn store_upload(&mut self, file_path: &Path) -> anyhow::Result<()> {
self.storage.store_file(file_path, false)
}
}
本项目采用 GPL-3.0-or-later 许可证。详见 LICENSE 文件。
欢迎提交 Issue 和 Pull Request。请确保在提交前运行测试:
cargo test