mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 05:16:44 +08:00
48 lines
1.8 KiB
Rust
48 lines
1.8 KiB
Rust
use bat_infrastructure::FileSystemCasRepository;
|
|
use bat_core::repositories::cas_repository::CasRepository;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
println!("🎮 BlueArchiveToolkit - CAS 存储演示");
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
|
|
// 创建 CAS Repository
|
|
let repo = FileSystemCasRepository::new("/tmp/bat-demo");
|
|
repo.init().await?;
|
|
println!("✅ CAS 存储已初始化");
|
|
|
|
// 存储一些数据
|
|
println!("\n📦 存储对象...");
|
|
let data1 = b"Hello, Blue Archive!";
|
|
let id1 = repo.store(data1).await?;
|
|
println!(" 存储对象 1: {}", &id1[..16]);
|
|
|
|
let data2 = b"This is a test file content";
|
|
let id2 = repo.store(data2).await?;
|
|
println!(" 存储对象 2: {}", &id2[..16]);
|
|
|
|
// 测试去重
|
|
println!("\n🔄 测试去重...");
|
|
let id1_dup = repo.store(data1).await?;
|
|
println!(" 相同内容再次存储: {}", &id1_dup[..16]);
|
|
println!(" 去重成功: {}", id1 == id1_dup);
|
|
|
|
// 获取对象
|
|
println!("\n📥 获取对象...");
|
|
let retrieved = repo.get(&id1).await?;
|
|
println!(" 原始数据: {:?}", String::from_utf8_lossy(data1));
|
|
println!(" 获取数据: {:?}", String::from_utf8_lossy(&retrieved));
|
|
println!(" 数据完整性: {}", data1 == retrieved.as_slice());
|
|
|
|
// 检查存在性
|
|
println!("\n🔍 检查对象存在性...");
|
|
println!(" 对象 1 存在: {}", repo.exists(&id1).await);
|
|
println!(" 对象 2 存在: {}", repo.exists(&id2).await);
|
|
println!(" 不存在的对象: {}", repo.exists(&"nonexistent".to_string()).await);
|
|
|
|
println!("\n✅ 演示完成!");
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
|
|
Ok(())
|
|
}
|