Table of Contents

Class ZstdDelta

Namespace
FishMMO.Shared
Assembly
FishMMO-SharedUtility.dll

Binary deltas between two versions of a file, as Zstandard frames that use the old file as a reference prefix (what zstd --patch-from does).

public static class ZstdDelta
Inheritance
ZstdDelta
Inherited Members

Remarks

Used by the native client patches: the patch generator stores each changed file as a delta against the version the player already has, and the Updater rebuilds the new file from the old one plus the delta. Unlike a same-offset chunk diff, a zstd match can point anywhere in the old file, so inserted or removed bytes do not invalidate everything after them; and a file Addressables renamed because a dependency's name inside it changed costs a few kilobytes instead of its whole size.

The reference file is memory-mapped and handed to zstd as a prefix, so neither side copies it into managed memory. A frame is a single zstd frame with the content size and a checksum, readable by the stock zstd tool (zstd -d --patch-from=old delta).

The window is sized from the larger of the two files, capped at MaxWindowLog (1 GiB), the largest window every decoder, 32-bit included, accepts. A file larger than MaxReferenceBytes cannot be referenced in full; callers ship such files whole (see CanReference(long, long)).

Fields

DefaultLevel

Default level: the smallest output, since patches are encoded once and downloaded many times.

public const int DefaultLevel = 22

Field Value

int

MaxLevel

Highest compression level zstd offers. Slow to encode, no slower to decode.

public const int MaxLevel = 22

Field Value

int

MaxReferenceBytes

Largest file (either side) a delta can fully reference.

public const long MaxReferenceBytes = 1073741824

Field Value

long

MaxWindowLog

Largest window log used or accepted (1 GiB).

public const int MaxWindowLog = 30

Field Value

int

Methods

CanReference(long, long)

True when a delta between files of these sizes can reference the whole of the old one.

public static bool CanReference(long referenceLength, long newLength)

Parameters

referenceLength long
newLength long

Returns

bool

Decode(string?, Stream, Stream, long)

Rebuilds a file from referencePath (the old version, or null for a delta written without one) and a delta written by Encode(string?, string, Stream, int).

public static long Decode(string? referencePath, Stream delta, Stream output, long expectedLength)

Parameters

referencePath string

The exact file the delta was made against, or null.

delta Stream

The delta stream; read to its end.

output Stream

Receives the rebuilt file.

expectedLength long

The rebuilt file's size; anything else is an error, and output beyond it is never written.

Returns

long

The number of bytes written.

Exceptions

InvalidDataException

The delta is corrupt, truncated, does not match the reference, or has trailing data.

Encode(string?, string, Stream, int)

Writes a delta that turns referencePath into newPath. A null referencePath writes plain zstd compression of the new file.

public static long Encode(string? referencePath, string newPath, Stream output, int level = 22)

Parameters

referencePath string
newPath string
output Stream
level int

Returns

long

The number of bytes written to output.

Exceptions

InvalidOperationException

Either file is larger than MaxReferenceBytes, or zstd reported an error.

WindowLogFor(long, long)

The window log for a delta between files of these sizes.

public static int WindowLogFor(long referenceLength, long newLength)

Parameters

referenceLength long
newLength long

Returns

int