Something went wrong. Try again.
BSDIFF40 binary diff and patch in pure OCaml
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132#!/usr/bin/env bash# Regenerate the committed traces against the reference bsdiff tool.## Writes, into the trace directory given as $1:# - source.bin, target.bin: deterministic inputs (no RNG, so the trace# diff stays reviewable)# - patch.bsdiff: the reference tool's patch from source.bin to target.bin# - bsdiff-version.txt: the oracle version## Needs bsdiff on PATH (brew install bsdiff).set -euo pipefailTRACE_DIR=$(cd "$1" && pwd)
python3 - "$TRACE_DIR/source.bin" "$TRACE_DIR/target.bin" <<'PY'import sysdef gen(n, mul, add): return bytes((i * mul + add + (i // 7)) & 0xff for i in range(n))source = gen(16384, 31, 7)# The target moves a window of the source, inserts new bytes, and nudges# every 50th byte by one: the shape bsdiff is designed for.body = source[100:12000] + b"freshly inserted bytes" + source[0:4000]target = bytes((b + 1) & 0xff if i % 50 == 0 else b for i, b in enumerate(body))open(sys.argv[1], "wb").write(source)open(sys.argv[2], "wb").write(target)PY
rm -f "$TRACE_DIR/patch.bsdiff"bsdiff "$TRACE_DIR/source.bin" "$TRACE_DIR/target.bin" "$TRACE_DIR/patch.bsdiff"{ brew list --versions bsdiff 2>/dev/null || echo "bsdiff (unknown version)"; } \ >"$TRACE_DIR/bsdiff-version.txt"echo "wrote $TRACE_DIR/{source,target}.bin and patch.bsdiff"