Expand description
The delta engine — ripsync’s crown jewel.
Given an old buffer and a new buffer, encode produces a compact
Delta: a sequence of Op::Copy (reuse a block of old) and
Op::Literal (raw bytes that aren’t in old) operations. apply stitches
those back together so that, for all inputs,
apply(old, encode(old, new, _)) == new§Algorithm
- Choose a block size
B = clamp(round(sqrt(old.len())), 700, 131072)(or an explicit override). - Split
oldinto blocks ofBbytes (the last may be short). For each block record its weak rolling checksum and strong hash, keyed weak → block indices. - Roll a
B-byte window acrossnew. When the weak checksum hits a known block and the strong hash confirms it, flush any pending literal run, emit aOp::Copy, and jump the window forward byB. Otherwise push the leftmost byte into the pending literal buffer and slide the window by one. - A short trailing block of
oldis matched against the remaining tail ofnew, so an unchanged file re-encodes to pure copies with zero literals.
Structs§
- Block
Sig - One block’s fingerprint inside a
Signature. - Delta
- A delta that reconstructs
newfromold. - Signature
- A compact fingerprint of an
oldbuffer: everything the delta encoder needs to find reusable blocks, and nothing else.
Enums§
- Op
- A single delta operation.
Constants§
- MAX_
BLOCK - Maximum auto-selected block size, in bytes.
- MIN_
BLOCK - Minimum auto-selected block size, in bytes.
Functions§
- apply
- Reconstruct
newby applyingdeltatoold. - block_
size_ for - Choose a block size for
old_len:clamp(round(sqrt(old_len)), 700, 131072). - encode
- Encode the difference from
oldtonew. - encode_
with_ signature - Encode
newagainst a previously computedSignatureofold.