Expand description
bitcut — create and apply binary patches.
The library exposes a small, allocation-friendly API:
make_patch/make_patch_into— produce a patch describing how to reconstructnewfromold.make_patch_stats/make_patch_into_stats— the same, also returningPatchStatsdescribing how the patch was found.apply_patch/apply_patch_into— apply a patch tooldand recovernew.Op/OpIter— low-level access to the patch opcode stream.inspect— read a patch’s header without applying it.
Both old and new are limited to u32::MAX (≈ 4 GiB) bytes.
§Patch format
Patches are written in the sectioned v2 layout, which names the base it
was built from; patches in the older opcode-stream layout are still read.
Both are described in the wire module.
A patch built from one base cannot be applied to another: old is
fingerprinted at build time and re-checked at apply time, and a mismatch
is PatchError::WrongBase rather than a plausible-looking wrong
document. The fingerprint is xxh3 — it detects a wrong or stale base, not
a forged patch. If patches arrive from somewhere untrusted, authenticate
them at the transport or storage layer.
§Matching
Matching is described in the differ module: the base is walked in
lockstep with the new document rather than indexed up front, so the search
cost tracks the number of edits rather than the size of the base. See
PatchStats for the counters that report when that assumption stops
holding.
§Cost
Hashing the base is one linear pass over old on both the build and the
apply side, and on a base large enough for the differ to skip most of it
that pass dominates. On the benchmark corpus (1.6 MiB base, local edits)
it is roughly 40 µs of the ~120 µs build and of the ~70 µs apply. A caller
that cannot afford it can compare PatchHeader::base_len and
base_fingerprint itself, once, and cache the result alongside the
base.
Structs§
- OpIter
- Iterator over the opcodes of a patch.
- Patch
Header - What a patch states about itself, readable without applying it.
- Patch
Stats - Counters describing how a patch was produced.
- Rolling
Hash - Iterator over rolling hashes of fixed-size windows.
Enums§
- Op
- A single patch opcode.
- Patch
Error - Errors produced by the patch deserializer / applier.
Functions§
- apply_
patch - Apply
patchtooldand return the reconstructed bytes. - apply_
patch_ into - Apply
patchinto a caller-supplied buffer. The buffer is not cleared first; reconstructed bytes are appended. - base_
fingerprint - Fingerprint a base document the way a v2 patch header records it.
- inspect
- Read a patch’s header without applying it.
- make_
patch - Build a patch describing how to reconstruct
newfromold. - make_
patch_ into - Build a patch into a caller-supplied buffer. The buffer is not cleared first; ops are appended.
- make_
patch_ into_ stats - Build a patch into a caller-supplied buffer and report how it was found. The buffer is not cleared first; ops are appended.
- make_
patch_ stats - Build a patch and report how it was found.