xdelta 3.0.0
dotnet add package xdelta --version 3.0.0
NuGet\Install-Package xdelta -Version 3.0.0
<PackageReference Include="xdelta" Version="3.0.0" />
<PackageVersion Include="xdelta" Version="3.0.0" />
<PackageReference Include="xdelta" />
paket add xdelta --version 3.0.0
#r "nuget: xdelta, 3.0.0"
#:package xdelta@3.0.0
#addin nuget:?package=xdelta&version=3.0.0
#tool nuget:?package=xdelta&version=3.0.0
XDeltaSharp
XDeltaSharp creates and applies VCDIFF binary patches in managed C#. For example, a game launcher can download a patch and reconstruct an updated asset bundle from the version already on disk. The NuGet package is named xdelta and its namespace is XDeltaSharp. It has no dependencies and ships builds for .NET 8, 9, 10, and 11.
- Exchange patches with the xdelta3 CLI using the standard VCDIFF code table and uncompressed sections.
- Apply a patch window by window from a stream, with limits on buffering and total output.
- Write patches to an
IBufferWriter<byte>and decode into a buffer you already own.
Create and apply your first patch
dotnet add package xdelta
The sender needs both versions to create the patch. The recipient needs the patch and the same original bytes.
using XDeltaSharp;
var original = "The quick brown fox jumps over the lazy dog."u8;
var updated = "The quick brown hare jumps over the lazy dog."u8;
byte[] patch = Vcdiff.Encode(original, updated);
byte[] restored = Vcdiff.Decode(original, patch);
Console.WriteLine(updated.SequenceEqual(restored)); // True
Performance against native xdelta3
These are median times per operation on two editions of Moby-Dick, 1.25 MB each, at level 3. XDeltaSharp produced a 21,287-byte patch and xdelta3 produced a 21,534-byte patch. To compare decoding on identical input, both decoders applied the xdelta3 patch.
| Host | XDeltaSharp encode | xdelta3 encode | Encode speedup | XDeltaSharp decode | xdelta3 decode |
|---|---|---|---|---|---|
| Apple M1 · macOS 15 | 2.29 ms | 5.58 ms | 2.43× | 0.21 ms | 0.22 ms |
| Intel Xeon 6975P-C · Ubuntu 24.04 | 2.55 ms | 3.47 ms | 1.36× | 0.20 ms | 0.22 ms |
| AMD EPYC 9V74 · Ubuntu 22.04 | 2.33 ms | 3.31 ms | 1.42× | 0.17 ms | 0.15 ms |
The benchmark runs .NET 11 and native xdelta3 3.2.2 in the same process, with inputs in memory and reusable output buffers. It takes the median of seven warmed batches and verifies that both decoders reconstruct the updated file byte for byte. Reproduce the comparison · Full results for levels 0–9 (CSV)
Other benchmarks cover encoding SQLite binaries and decoder allocations for array, span, and stream output.
Apply an update to a file
using XDeltaSharp;
using var original = File.OpenRead("original.bin");
using var patch = File.OpenRead("update.vcdiff");
using var restored = File.Create("restored.bin");
Vcdiff.Decode(original, patch, restored);
The decoder reads the patch sequentially and leaves all three streams open. When a patch copies from the original, the source must be readable and seekable. When it copies from a previous output window, the destination must also support reading and seeking.
A failed decode can leave a partially written file. When installing an update, decode to a temporary file, verify it against the expected digest from your release manifest, then replace the installed file.
Set decoding limits
A patch states its own sizes. When accepting downloaded patches, choose limits that fit the files you expect. In the file example, replace the Vcdiff.Decode call with the following to cap the encoded window, the decoded window, and the whole update independently.
const int MiB = 1024 * 1024;
Vcdiff.Decode(original, patch, restored, new VcdiffDecodeOptions
{
MaxEncodedWindowBytes = 4 * MiB,
MaxWindowBytes = 8 * MiB,
MaxOutputBytes = 64 * MiB
});
The defaults are Array.MaxLength encoded bytes per window, 64 MiB per decoded window, and no limit on total output. The same options apply to the array and span decoders, where MaxEncodedWindowBytes has no effect because the patch is already in memory.
Use your own buffers
The encoder can append to any IBufferWriter<byte>. If you know the updated file size, supply a destination span to the decoder and use the returned byte count to read the result.
using System.Buffers;
using XDeltaSharp;
var original = File.ReadAllBytes("original.bin");
var updated = File.ReadAllBytes("updated.bin");
var patch = new ArrayBufferWriter<byte>();
Vcdiff.Encode(original, updated, patch);
var buffer = new byte[updated.Length];
int written = Vcdiff.Decode(original, patch.WrittenSpan, buffer.AsSpan());
ReadOnlySpan<byte> restored = buffer.AsSpan(0, written);
Tune the encoder
Pass a VcdiffEncodeOptions as the last argument to either Encode method.
| Goal | Option |
|---|---|
| Search more thoroughly for matches (levels 0–9, default 3) | CompressionLevel = 9 |
| Spend extra encoding time to try for a smaller patch | Optimize = true |
| Halve the number of buckets in the match indexes | MemoryMode = MemoryMode.LessMemory |
Exchange patches with xdelta3
The core package reads and writes uncompressed VCDIFF sections using the default code table. To create a patch that the core decoder can read, disable secondary compression in xdelta3 with -S none. VCDIFF specification (RFC 3284)
# Create a patch for XDeltaSharp with xdelta3
xdelta3 -e -S none -s original.bin updated.bin update.vcdiff
# Apply an XDeltaSharp patch with xdelta3
xdelta3 -d -s original.bin update.vcdiff restored.bin
| If your patch uses… | Install | Use |
|---|---|---|
| LZMA secondary compression | xdelta.Lzma | LzmaVcdiff.Decode(original, patch) |
| Embedded BLAKE3 digests | xdelta.Blake3 | new VcdiffDecodeOptions { Armor = Blake3Armor.Verify } |
Testing and contributing
CI runs the test suite on Windows and Linux, and checks interoperability with the xdelta3 CLI on Linux. Native AOT, trimming, and Unity are untested. Report bugs or ask questions in GitHub Issues. For local setup, fixture details, and instructions for running the package examples, see the contributing guide.
License
XDeltaSharp is available under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on xdelta:
| Package | Downloads |
|---|---|
|
xdelta.Lzma
Apply xdelta3 VCDIFF patches with LZMA secondary compression in .NET 8. Decode mixed raw and compressed sections across windows to an array, span, or stream. |
|
|
xdelta.Blake3
Verify whole-file source and target digests in xdelta3 BLAKE3 armor. Adds opt-in verification to the XDeltaSharp core and LZMA decoders on .NET 8. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Breaking: settings moved from optional parameters to options objects. Pass a VcdiffEncodeOptions (CompressionLevel, MemoryMode, Optimize) to Vcdiff.Encode and a VcdiffDecodeOptions (MaxOutputBytes, MaxWindowBytes, MaxEncodedWindowBytes, Armor) to Vcdiff.Decode. LzmaVcdiff.Decode takes an LzmaDecodeOptions, which adds MaxExpandedSectionBytes and MaxDictionaryBytes. DecodeWithLimits and DecodeWithSecondaryLimits are removed. Patch bytes are unchanged.