zsync-rs
A fast, pure Rust implementation of zsync — the efficient file transfer algorithm that downloads only the parts of a file you don't already have.
How it works
zsync uses the rsync rolling checksum algorithm over HTTP. Given an old version of a file, it identifies which blocks are unchanged and downloads only the differences:
- Fetches the
.zsynccontrol file (block checksums for the target file) - Scans local seed files for matching blocks using rolling checksums
- Downloads only the missing blocks via HTTP range requests
- Assembles the final file and verifies its SHA-1 checksum
Features
- Accurate matching — sequential block chaining, proper
rsum_a_maskhandling, and zero-padded EOF scanning match the reference C implementation exactly - Fast lookups — flat hash table with a bithash for O(1) negative filtering, matching the C data structure design
- Parallel scanning — splits large source files across CPU cores for matching (something the single-threaded C implementations can't do)
- Optimized downloads — merges HTTP range requests to minimize round-trips
- Multiple seed files — pass multiple
-iflags to scan several local files - Self-referential scanning — after seed matching, scans the partially-assembled output to find duplicate target blocks without downloading them
- Fuzz-tested — control file parser, rolling checksums, and block matcher are all fuzz-tested with cargo-fuzz
Installation
Usage
# Basic: download a file using its .zsync control file
# Use a local file as seed to avoid re-downloading unchanged blocks
# Multiple seed files for maximum local matching
# Specify output filename
Library Usage
zsync-rs is library-first — the CLI is a thin wrapper around the public API:
use Path;
use ZsyncAssembly;
let mut assembly = from_url?;
// Match blocks from a local seed file
assembly.submit_source_file?;
// Download whatever's missing
while !assembly.is_complete
// Verify checksum and finalize
assembly.complete?;
Building
Testing
# Fuzzing (requires nightly)