Essential delta-transfer idea behind rsync.
NOTE:This project is not rsync and is not compatible with the rsync wire protocol.
Suppose a receiver already has an older source file, while a sender has a modified target file.
Instead of transferring the entire target, this demo:
- splits the source into fixed-size blocks;
- calculates a cheap rolling checksum and SHA-256 for each source block;
- scans the target byte-by-byte;
- uses rolling checksum updates to locate candidate shifted blocks;
- verifies candidates with SHA-256;
- emits:
COPY(block)for bytes already available in the source;DATA(bytes)for new/changed bytes;
- reconstructs the target from the source and delta;
- verifies exact byte equality.
The rolling checksum is intentionally cheap and can be updated in O(1) when the scan window moves one byte.
It is only a filter: weak checksums can collide.
SHA-256 provides strong verification, but it is more expensive. The scanner therefore calculates target SHA-256 only when the weak checksum finds one or more candidate source blocks.
Conceptually:
target window
│
├─ weak checksum has no source candidate ──> slide by one byte
│
└─ weak checksum has candidate(s)
│
└─ SHA-256 once
│
├─ strong match ──> COPY(block)
└─ no match ─────> slide by one byte
cargo run --release -- diff \
examples/source.txt \
examples/target.txt \
--block-size 16 \
--delta artifacts/example.rsdd \
--html artifacts/report.html \
--verbosecargo run --release -- inspect artifacts/example.rsddcargo run --release -- apply \
examples/source.txt \
artifacts/example.rsdd \
artifacts/reconstructed.txtVerify externally:
cmp examples/target.txt artifacts/reconstructed.txtcargo run --release -- benchmark \
examples/source.txt \
examples/target.txt \
--blocks 4,8,16,32,64The demo reports:
- source size;
- target size;
- block size;
- source block count;
- COPY/DATA operation counts;
- reused bytes;
- literal/transferred bytes;
- matching percentage;
- actual serialized delta size;
- source SHA-256 operations;
- target SHA-256 operations;
- weak candidate hits;
- rolling checksum updates;
- timings;
- verification status.
diff --html report.html creates a self-contained report showing the target as reused and transferred regions.
The report includes:
- summary metrics;
- target operation strip;
- COPY/DATA legend;
- operation table;
- checksum/hash counters;
- timings.
benchmark --html report.html can additionally include block-size comparison results.
src/checksum.rs rolling weak checksum
src/signature.rs source block signatures/index
src/scanner.rs target scan and delta generation
src/delta.rs core delta models
src/codec.rs .rsdd binary encoding
src/reconstruct.rs source + delta reconstruction
src/stats.rs metrics
src/benchmark.rs block-size comparison
src/html.rs self-contained report
src/main.rs CLI only
The MVP deliberately does not implement:
- networking;
- directory synchronization;
- metadata/permissions;
- compression;
- encryption;
- remote authentication;
- sparse-file optimization;
- streaming huge files;
- the actual rsync protocol.
The goal is to make the matching algorithm understandable.
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-targets
cargo build --releasedocs/ALGORITHM.mdexplains the rolling-checksum matching design.docs/DELTA_FORMAT.mddocuments the strict.rsddbinary format.docs/CLI_SPEC.mddescribes commands, options, and output behavior.docs/HTML_REPORT.mddescribes the self-contained visualization.
MIT