BSDIFF40 binary diff and patch library with bounded resources and a native CLI
moon update
python scripts/build_cli.py --releasepython scripts/run_update_demo.py --cli _build/bin/windows/moonbsdiff.exepython scripts/run_update_demo.py --cli _build/bin/linux/moonbsdiffmoon info
moon fmt
moon fmt --check
moon check --target native --deny-warn
moon build --target native
moon test --target native --deny-warn
python scripts/check_format_vectors.py
python scripts/check_compression.py
python scripts/check_apply.py
git diff --checktest "apply-memory-example" {
let stream = b"BZh9\x17\x72\x45\x38\x50\x90\x00\x00\x00\x00"
let patch = b"BSDIFF40" +
b"\x0e\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
stream +
stream +
stream
let limits : @moonbsdiff.Limits = {
max_old_bytes: 1024L,
max_new_bytes: 1024L,
max_patch_bytes: 1024L,
max_output_bytes: 1024L,
max_decompressed_bytes: 4096L,
max_control_instructions: 128L,
max_sort_work: 1L,
max_match_work: 1L,
}
assert_eq(@moonbsdiff.apply(b"", patch, limits), Ok(b""))
}let limits = @moonbsdiff.Limits::for_apply()
// old_bytes and patch_bytes are supplied by the caller.
let result = @moonbsdiff.apply(old_bytes, patch_bytes, limits)test "diff-memory-example" {
let limits : @moonbsdiff.Limits = {
max_old_bytes: 4096L,
max_new_bytes: 4096L,
max_patch_bytes: 8192L,
max_output_bytes: 4096L,
max_decompressed_bytes: 16384L,
max_control_instructions: 256L,
max_sort_work: 1000000L,
max_match_work: 1000000L,
}
let old = b"MoonBSDiff example version 1"
let new = b"MoonBSDiff example version 2!"
let patch = match @moonbsdiff.diff(old, new, limits) {
Ok(b) => b
Err(_) => abort("diff failed")
}
assert_eq(@moonbsdiff.apply(old, patch, limits), Ok(new))
}let limits = @moonbsdiff.Limits::for_diff()
let result = @moonbsdiff.diff(old_bytes, new_bytes, limits)python scripts/build_cli.py& .\_build\bin\windows\moonbsdiff.exe --help
& .\_build\bin\windows\moonbsdiff.exe --version
& .\_build\bin\windows\moonbsdiff.exe diff "old file.bin" "new file.bin" "update.patch"
& .\_build\bin\windows\moonbsdiff.exe patch "old file.bin" "update.patch" "restored file.bin"./_build/bin/linux/moonbsdiff diff 'old file.bin' 'new file.bin' 'update.patch'
./_build/bin/linux/moonbsdiff patch 'old file.bin' 'update.patch' 'restored file.bin'./_build/bin/linux/moonbsdiff diff --max-old-bytes 256KiB --show-limits
./_build/bin/linux/moonbsdiff patch --show-limits./_build/bin/linux/moonbsdiff inspect testdata/upstream/replace/patch.bin
./_build/bin/linux/moonbsdiff inspect --json --max-patch-bytes 256KiB testdata/upstream/replace/patch.bin./_build/bin/linux/moonbsdiff diff --manifest update.json old.bin new.bin update.patch./_build/bin/linux/moonbsdiff verify --manifest update.json old.bin update.patch
./_build/bin/linux/moonbsdiff patch --manifest update.json old.bin update.patch restored.binfn publish_update(old : Bytes, new : Bytes) -> Result[@manifest.PatchBundle, @moonbsdiff.BsdiffError] {
@manifest.diff(old, new, @moonbsdiff.Limits::for_diff())
}
fn restore_bundle(old : Bytes, patch : Bytes, trusted_manifest : Bytes) -> Result[Bytes, @manifest.ManifestError] {
@manifest.apply(old, patch, trusted_manifest, @moonbsdiff.Limits::for_apply())
}fn choose_download(
installed : Bytes,
target : @manifest.PreparedManifest,
candidates : Array[@manifest.PreparedManifest],
max_steps : Int64,
) -> Result[@manifest.UpdatePlan, @manifest.PlanError] {
@manifest.plan_update(
@manifest.ContentIdentity::of_bytes(installed),
target.new,
candidates,
max_steps=max_steps,
)
}moonbsdiff manifest plan --allow-full --max-steps 1 --target-manifest v2-to-v3.json -- installed.bin v1-to-v2.json v2-to-v3.json v1-to-v3.jsonmoonbsdiff install-full --target-manifest v2-to-v3.json -- downloaded-v3.bin restored.binmoon run cmd/example --target js
python scripts/run_examples.pymoon add BigSaltyMan/moonbsdiff@0.1.0pub(all) struct BsdiffError {
kind : ErrorKind
stage : ErrorStage
block : String?
offset : Int64?
field : String?
value : Int64?
limit : Int64?
} derive(Eq, Debug)pub struct DeepPatchInfo {
header : PatchInfo
control_count : Int64
diff_bytes : Int64
extra_bytes : Int64
expanded_bytes : Int64
}pub struct DiffIndex {
// private fields
}fn DiffIndex::diff(self : DiffIndex, new_bytes : Bytes, limits : Limits) -> Result[Bytes, BsdiffError]fn DiffIndex::diff_with_options(self : DiffIndex, new_bytes : Bytes, limits : Limits, options : DiffOptions) -> Result[Bytes, BsdiffError]pub(all) struct DiffOptions {
compression_level : Int
}pub struct PatchInfo {
patch_bytes : Int64
new_bytes : Int64
control_start : Int64
control_length : Int64
diff_start : Int64
diff_length : Int64
extra_start : Int64
extra_length : Int64
}fn diff_with_options(old_bytes : Bytes, new_bytes : Bytes, limits : Limits, options : DiffOptions) -> Result[Bytes, BsdiffError]fn inspect_header_prefix(data : Bytes, patch_bytes : Int64, max_patch_bytes : Int64) -> Result[PatchInfo, BsdiffError]