Skip to main content

Module delta

Module delta 

Source
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

  1. Choose a block size B = clamp(round(sqrt(old.len())), 700, 131072) (or an explicit override).
  2. Split old into blocks of B bytes (the last may be short). For each block record its weak rolling checksum and strong hash, keyed weak → block indices.
  3. Roll a B-byte window across new. When the weak checksum hits a known block and the strong hash confirms it, flush any pending literal run, emit a Op::Copy, and jump the window forward by B. Otherwise push the leftmost byte into the pending literal buffer and slide the window by one.
  4. A short trailing block of old is matched against the remaining tail of new, so an unchanged file re-encodes to pure copies with zero literals.

Structs§

BlockSig
One block’s fingerprint inside a Signature.
Delta
A delta that reconstructs new from old.
Signature
A compact fingerprint of an old buffer: 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 new by applying delta to old.
block_size_for
Choose a block size for old_len: clamp(round(sqrt(old_len)), 700, 131072).
encode
Encode the difference from old to new.
encode_with_signature
Encode new against a previously computed Signature of old.