Documentation
¶
Overview ¶
Package delta implements rsync-style rolling checksums and block matching for efficient partial file transfers.
Index ¶
Constants ¶
const DefaultBlockSize = 4096
DefaultBlockSize is used when a caller does not specify a block size.
const MaxDecodeOps = 16 << 20 // 16M
MaxDecodeOps caps ops/blocks allocated when unmarshalling untrusted wire data. Bounded well below MaxMessageSize-scale payloads (each op is at least 1 byte).
const MaxOutputSize = 64 << 20 // 64 MiB
MaxOutputSize caps reconstructed file size from a delta (matches typical MaxFileBytes / proto framing). Rejects malicious OutputSize before allocate.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply reconstructs the target file by applying d against basis. basis must be the full original file contents that produced the signature.
func MarshalDelta ¶
MarshalDelta serializes a Delta to a compact binary form. Format: magic(4) blockSize(u32) outputSize(u64) nOps(u32) then ops. OpLiteral: kind(u8) len(u32) data OpCopy: kind(u8) blockIndex(u32)
func MarshalSignature ¶
MarshalSignature serializes a Signature for the wire protocol.
Types ¶
type BlockChecksum ¶
type BlockChecksum struct {
// Index is the block number in the basis file.
Index int `json:"index"`
// Weak is the Adler-32-like rolling checksum.
Weak uint32 `json:"weak"`
// Strong is MD5 of the block for match-only candidate confirmation (rsync-like).
// MD5 is not a security boundary: after apply, the full file is verified with
// SHA-256 against the manifest hash before commit.
Strong [md5.Size]byte `json:"strong"`
}
BlockChecksum holds weak (rolling) and strong checksums for one block.
type Delta ¶
Delta is a sequence of ops that reconstruct a target file from a basis.
func EncodeBytes ¶
EncodeBytes is Encode over an in-memory buffer.
func UnmarshalDelta ¶
UnmarshalDelta parses a binary delta produced by MarshalDelta.
type Op ¶
type Op struct {
Kind OpKind
// Data is set for OpLiteral.
Data []byte
// BlockIndex is set for OpCopy (index into the basis signature).
BlockIndex int
}
Op is one instruction in a delta: either a literal run or a basis block copy.
type Signature ¶
type Signature struct {
BlockSize int `json:"block_size"`
Blocks []BlockChecksum `json:"blocks"`
}
Signature describes the block layout of a basis file (the version the receiver already has).
func UnmarshalSignature ¶
UnmarshalSignature parses a signature from MarshalSignature.