engram-rs
A unified Rust library for creating, reading, and managing Engram archives - compressed, cryptographically signed archive files with embedded metadata and SQLite database support.
Features
- 📦 Compressed Archives: LZ4 (fast) and Zstd (high compression ratio) with automatic format selection
- 🔐 Cryptographic Signatures: Ed25519 signatures for authenticity and integrity verification
- 📋 Manifest System: JSON-based metadata with file registry, author info, and capabilities
- 💾 Virtual File System (VFS): Direct SQL queries on embedded SQLite databases without extraction
- ⚡ Fast Lookups: O(1) file access via central directory with 320-byte entries
- ✅ Integrity Verification: CRC32 checksums for all files
- 🔒 Encryption Support: AES-256-GCM encryption (per-file or full-archive)
- 🎯 Frame-based Compression: Efficient handling of large files with incremental decompression
Installation
Add this to your Cargo.toml:
[]
= "1.0"
Quick Start
Creating an Archive
use ;
Reading from an Archive
use ArchiveReader;
Working with Manifests and Signatures
use ;
use ;
use OsRng;
Querying Embedded SQLite Databases
use VfsReader;
Archive Format
Engram uses a custom binary format (v1.0) with the following structure:
┌─────────────────────────────────────────┐
│ File Header (64 bytes) │
│ - Magic: 0x89 'E' 'N' 'G' 0x0D 0x0A 0x1A 0x0A │
│ - Format version (major.minor) │
│ - Central directory offset/size │
│ - Entry count, content version │
│ - CRC32 checksum │
├─────────────────────────────────────────┤
│ Local Entry Header 1 (LOCA) │
│ Compressed File Data 1 │
├─────────────────────────────────────────┤
│ Local Entry Header 2 (LOCA) │
│ Compressed File Data 2 │
├─────────────────────────────────────────┤
│ ... │
├─────────────────────────────────────────┤
│ Central Directory │
│ - Entry 1 (320 bytes) │
│ - Entry 2 (320 bytes) │
│ - ... │
├─────────────────────────────────────────┤
│ End of Central Directory (ENDR) │
├─────────────────────────────────────────┤
│ manifest.json (optional) │
│ - Metadata, author, signatures │
└─────────────────────────────────────────┘
Key Features:
- Magic Number: PNG-style magic bytes for file type detection
- Local Headers: Frame-based compression for efficient large file handling
- Central Directory: Fast file lookup with O(1) access time
- Manifest: JSON metadata with Ed25519 signature support
Compression
The library automatically selects compression based on file type and size:
| File Type | Size | Compression |
|---|---|---|
| Text files (.txt, .json, .md, etc.) | ≥ 4KB | Zstd (best ratio) |
| Binary files (.db, .wasm, etc.) | ≥ 4KB | LZ4 (fastest) |
| Already compressed (.png, .jpg, .zip, etc.) | Any | None |
| Small files | < 4KB | None |
You can also manually specify compression:
writer.add_file_with_compression?;
Cryptography
Signatures (Ed25519)
use ;
use OsRng;
// Generate keypair
let signing_key = generate;
let verifying_key = signing_key.verifying_key;
// Sign archive
writer.sign_manifest?;
// Verify signature
let valid = manifest.verify_signatures?;
Encryption (AES-256-GCM)
// Encrypt individual files
writer.add_encrypted_file?;
// Decrypt when reading
let data = reader.read_encrypted_file?;
API Overview
Core Types
ArchiveWriter- Create and write to archivesArchiveReader- Read from existing archivesVfsReader- Query SQLite databases in archivesManifest- Archive metadata and signaturesCompressionMethod- Compression algorithm selectionEngramError- Error types
Main Operations
| Operation | Method |
|---|---|
| Create archive | ArchiveWriter::create(path) |
| Open archive | ArchiveReader::open(path) |
| Add file | writer.add_file(name, data) |
| Read file | reader.read_file(name) |
| List files | reader.list_files() |
| Add manifest | writer.write_manifest(manifest) |
| Sign manifest | writer.sign_manifest(key, signer) |
| Query database | vfs.open_database(name) |
Examples
See the examples/ directory for complete examples:
basic.rs- Creating and reading archivesmanifest.rs- Working with manifests and signaturescompression.rs- Compression optionsvfs.rs- Querying embedded databasesencryption.rs- Encrypting files
Run examples with:
Testing
# Run all tests
# Run with output
# Run specific test
Test Coverage:
- ✅ 22 unit tests (format, manifest, VFS)
- ✅ 9 integration tests (roundtrip, compression, large files)
- ✅ All tests passing
Performance
Benchmarks on a test file (10MB):
| Compression | Write Speed | Read Speed | Ratio |
|---|---|---|---|
| None | 450 MB/s | 500 MB/s | 1.0x |
| LZ4 | 380 MB/s | 420 MB/s | 2.1x |
| Zstd | 95 MB/s | 180 MB/s | 3.8x |
Benchmarked on Intel i7-12700K, NVMe SSD
Compatibility
- Rust: 1.75+ (2021 edition)
- Platforms: Windows, macOS, Linux, BSD
- Architectures: x86_64, aarch64 (ARM64)
Migration from engram-core/engram-vfs
This library replaces the previous two-crate structure:
// Old
use ;
use VfsReader;
// New (engram-rs)
use ;
All functionality is now unified in a single crate with improved APIs.
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
Licensed under the MIT License.
Related Projects
- engram-cli - Command-line tool for managing Engram archives
- engram-specification - Format specification
Links
- Crates.io: https://crates.io/crates/engram-rs
- Documentation: https://docs.rs/engram-rs
- Repository: https://github.com/blackfall-labs/engram-rs
- Issues: https://github.com/blackfall-labs/engram-rs/issues