| Crates.io | xpatch |
| lib.rs | xpatch |
| version | 0.4.2 |
| created_at | 2025-12-07 21:59:52.001603+00 |
| updated_at | 2026-01-11 23:38:08.923217+00 |
| description | High-performance delta compression library with automatic algorithm selection |
| homepage | https://github.com/ImGajeed76/xpatch |
| repository | https://github.com/ImGajeed76/xpatch |
| max_upload_size | |
| id | 1972336 |
| size | 481,245 |
A high-performance delta compression library with automatic algorithm selection.
[dependencies]
xpatch = "0.3.1"
Requirements:
use xpatch::delta;
fn main() {
let base = b"Hello, World!";
let new = b"Hello, Rust!";
// Create delta
let delta = delta::encode(0, base, new, true);
// Apply delta
let reconstructed = delta::decode(base, &delta).unwrap();
assert_eq!(reconstructed, new);
// Extract tag
let tag = delta::get_tag(&delta).unwrap();
println!("Compressed {} → {} bytes", new.len(), delta.len());
}
encodepub fn encode(tag: usize, base_data: &[u8], new_data: &[u8], enable_zstd: bool) -> Vec<u8>
Creates a delta that transforms base_data into new_data.
tag: User-defined metadata value (tags 0-15 use zero overhead)base_data: The original datanew_data: The target dataenable_zstd: Enable zstd compression for complex changes (slower but better compression)Returns: Compact delta as bytes
decodepub fn decode(base_data: &[u8], delta: &[u8]) -> Result<Vec<u8>, &'static str>
Applies a delta to reconstruct the new data.
base_data: The original data the delta was created fromdelta: The encoded deltaReturns: Reconstructed data or error
get_tagpub fn get_tag(delta: &[u8]) -> Result<usize, &'static str>
Extracts the tag value from a delta without decoding it.
Returns: Tag value or error
Install the CLI tool with:
cargo install xpatch --features cli
Usage:
# Create a delta
xpatch encode base.txt new.txt -o patch.xp
# Apply a delta
xpatch decode base.txt patch.xp -o restored.txt
# Show delta info
xpatch info patch.xp
Tested on 1.2+ million real-world git changes:
xpatch analyzes the change pattern and automatically selects the most efficient algorithm:
For complex changes, xpatch uses gdelta, a general-purpose delta compression algorithm, with optional zstd compression.
See the examples directory:
Run examples with:
cargo run --example basic
cargo run --example tags
Run the comprehensive benchmark suite:
# Quick stress tests
cargo bench --bench stress
# Real-world git repository benchmarks
XPATCH_PRESET=tokio cargo bench --bench git_real_world
Dual-licensed under AGPL-3.0-or-later or commercial license. See LICENSE-AGPL.txt and LICENSE-COMMERCIAL.txt.
For commercial licensing inquiries: xpatch-commercial@alias.oseifert.ch