.zdelta Files
Generate and apply zstd-compressed single patches and tar containers.
The zdelta cargo feature adds file-level helpers on top of the diffing
engine: zstd compression and tar containers for shipping diffs.
[dependencies]
zbsdiff = { version = "1.6", features = ["zdelta"] }A .zdelta file is a zstd frame holding one of two shapes:
- Single-target shape: the decompressed payload is a raw bsdiff patch
(magic
BSDIFF40) transforming exactly one source into one target. - Container shape: the decompressed payload is a tar archive holding a
meta.jsondescriptor plus one or more patch or payload files, used when several files change together (for example pooled package archives). Containers written bywrite_containercarry the format identifierzoi.zdelta.v1inmeta.json.
Generating a container
use serde_json::json;
use zbsdiff::zdelta;
let patch = zdelta::diff_bytes(old_bytes, new_bytes)?;
let meta = json!({
"format": zdelta::ZDELTA_FORMAT_ID,
"entries": ["data.bsdiff"],
});
zdelta::write_container(
&meta,
&[("data.bsdiff".to_string(), patch)],
"update.zdelta".as_ref(),
)?;Use write_container_bytes when the compressed bytes should stay in
memory, and zstd_compress for compressing a raw single patch.
Applying a .zdelta file
use zbsdiff::zdelta::{self, ZDelta};
let rebuilt = match zdelta::load("update.zdelta".as_ref())? {
ZDelta::Container(_, files) => {
let patch = files.get("data.bsdiff").expect("patch entry");
zdelta::apply_bytes(old_bytes, patch)?
}
ZDelta::Single(patch) => zdelta::apply_bytes(old_bytes, &patch)?,
};load (and load_bytes) detects either shape automatically. Decompression
is capped at 64 GiB of output per file. See the
custom formats guide for
decoupling the diffing engine from storage entirely.
2026 © All Rights Reserved.
- All the content is available under CC BY-SA 4.0, expect where otherwise stated.
- Source code is available on GitLab, licensed under Apache 2.0.
Last updated on
