| Crates.io | casq_core |
| lib.rs | casq_core |
| version | 0.8.2 |
| created_at | 2026-01-22 21:45:55.370508+00 |
| updated_at | 2026-01-25 18:51:26.05737+00 |
| description | A minimal content-addressed file store using BLAKE3. (library) |
| homepage | |
| repository | https://github.com/roobie/casq |
| max_upload_size | |
| id | 2062683 |
| size | 189,888 |
A production-ready content-addressed file store (CAS) library with compression and chunking (v0.4.0).
casq_core is a Rust library that provides the core functionality for casq, a content-addressed storage system with modern efficiency features. It stores files and directories by their cryptographic hash, ensuring immutable, deduplicated storage with transparent compression, content-defined chunking, and built-in garbage collection.
Think of it as a minimal git object store or restic backend, but with compression and chunking for storage efficiency.
.gitignore during filesystem walksuse casq_core::{Store, Algorithm};
use std::path::Path;
// Initialize a new store
let store = Store::init("./my-store", Algorithm::Blake3)?;
// Add a file or directory
let hash = store.add_path(Path::new("./my-data"))?;
// Create a named reference (GC root)
store.refs().add("backup-2024", &hash)?;
// Garbage collect unreferenced objects
let stats = store.gc(false)?;
println!("Deleted {} objects, freed {} bytes",
stats.objects_deleted, stats.bytes_freed);
// Materialize back to filesystem
store.materialize(&hash, Path::new("./restored"))?;
Objects are stored with a 16-byte header followed by the payload.
Object format:
0x00 4 "CAFS" magic
0x04 1 version (u8) = 2
0x05 1 type: 1=blob, 2=tree, 3=chunk_list
0x06 1 algo: 1=blake3-256
0x07 1 compression: 0=none, 1=zstd
0x08 8 payload_len (u64 LE) - compressed size if compressed
0x10 ... payload (possibly compressed)
$STORE_ROOT/
config # Store configuration (version, algorithm)
objects/
blake3-256/ # Algorithm-specific directory
ab/ # First 2 hex chars (shard)
abcd...ef # Remaining 62 hex chars (object file)
refs/ # Named references (GC roots)
backup-name
casq_core/src/
├── lib.rs - Public API and documentation
├── error.rs - Error types with thiserror
├── hash.rs - BLAKE3 hashing (32-byte digests)
├── object.rs - Binary object encoding/decoding
├── chunking.rs - Content-defined chunking with FastCDC (v0.4.0+)
├── store.rs - Store management with compression/chunking
├── tree.rs - Tree entry encoding with canonical sorting
├── walk.rs - Filesystem traversal with gitignore
├── gc.rs - Garbage collection (mark & sweep, handles all object types)
├── refs.rs - Reference management
└── journal.rs - Operation journal
# Build the library
cargo build --release -p casq_core
# Run all tests (121 unit tests + 23 property tests + 1 doctest)
cargo test -p casq_core
# Run only property tests
cargo test -p casq_core prop
# Run with output
cargo test -p casq_core -- --nocapture
# Check code quality
cargo clippy -p casq_core -- -D warnings
# Format code
cargo fmt -p casq_core
Store - Main store interfaceHash - 32-byte BLAKE3 hash wrapperTreeEntry - File/directory entry in a treeRefManager - Manages named referencesGcStats - Garbage collection statistics// Store initialization
let store = Store::init(path, Algorithm::Blake3)?;
let store = Store::open(path)?;
// Object storage
let hash = store.put_blob(reader)?;
let hash = store.put_tree(entries)?;
let hash = store.add_path(path)?; // Recursively add file/dir
// Object retrieval
let data = store.get_blob(&hash)?;
let entries = store.get_tree(&hash)?;
store.cat_blob(&hash, writer)?;
// Materialization
store.materialize(&hash, dest_path)?;
// References
store.refs().add(name, &hash)?;
let hash = store.refs().get(name)?;
let all_refs = store.refs().list()?;
store.refs().remove(name)?;
// Garbage collection
let stats = store.gc(dry_run)?;
hash = blake3(uncompressed_payload_bytes) (payload only, not header)hash = blake3(original_file_bytes) (not the ChunkList metadata)objects/<algo>/<prefix>/<suffix> where prefix is first 2 hex charsrefs/ directory✓ 121 unit tests passing (100% pass rate)
✓ 23 property tests (generative invariant verification)
✓ 1 doctest passing
✓ 100% core functionality coverage
✓ Edge cases: corruption, empty files/dirs, large files, permissions
✓ Round-trip testing: add → store → materialize → verify
✓ Compression/chunking: thresholds, boundaries, deduplication
Unit Tests:
Property Tests:
The following are intentionally not supported:
Note: Compression and chunking are now supported in v0.4.0+
Storage Efficiency:
All operations return Result<T, Error> with detailed error types:
IoError - File system operationsCorruptedObject - Hash mismatch or invalid formatInvalidHash - Malformed hash stringObjectNotFound - Missing object in storeInvalidStore - Store not initialized or corrupted configInvalidRef - Bad reference name or formatPathExists - Destination already exists (materialization)blake3 = "1.5" # BLAKE3 hashing
hex = "0.4" # Hash hex encoding/decoding
tempfile = "3.0" # Atomic object writes
ignore = "0.4" # Filesystem walking with .gitignore support
thiserror = "2.0" # Error handling
zstd = "0.13" # Transparent compression (v0.4.0+)
fastcdc = "3.1" # Content-defined chunking (v0.4.0+)
This library is part of the casq project. When contributing:
cargo test -p casq_corecargo clippy -p casq_core -- -D warningscargo fmt -p casq_coreApache-2.0