Skip to main content

Crate bitcut

Crate bitcut 

Source
Expand description

bitcut — create and apply binary patches.

The library exposes a small, allocation-friendly API:

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.
PatchHeader
What a patch states about itself, readable without applying it.
PatchStats
Counters describing how a patch was produced.
RollingHash
Iterator over rolling hashes of fixed-size windows.

Enums§

Op
A single patch opcode.
PatchError
Errors produced by the patch deserializer / applier.

Functions§

apply_patch
Apply patch to old and return the reconstructed bytes.
apply_patch_into
Apply patch into 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 new from old.
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.