chunker

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package chunker implements the buzhash content-defined chunker used by Proxmox Backup Server (a port of pbs-datastore's chunker): a 64-byte rolling window over the casync hash table, cutting chunks between min (avg/4) and max (avg*4) with a 4 MiB default average.

Index

Constants

View Source
const DefaultAvg = 4 << 20

DefaultAvg is the chunk size target Proxmox Backup Server uses.

Variables

This section is empty.

Functions

func Split

func Split(r io.Reader, avg uint64) iter.Seq2[Chunk, error]

Split reads r to EOF and yields its content-defined chunks in order. The final chunk may be shorter than the minimum. A read error is yielded as the last element with a zero Chunk.

Types

type Chunk

type Chunk struct {
	Data   []byte // owned by the consumer
	Offset uint64 // start offset within the stream
}

Chunk is one content-defined chunk of a stream.

type Chunker

type Chunker struct {
	// contains filtered or unexported fields
}

Chunker is the buzhash content-defined chunker used by Proxmox Backup Server (a port of pbs-datastore's chunker.rs). Boundaries depend only on content, so a changed byte resynchronizes within roughly one window.

Chunks are cut between min (avg/4) and max (avg*4): below min no boundary is considered, above max one is forced, in between a boundary falls where hash & (2*avg-1) lands in the top three values — matching the reference implementation bit for bit.

func New

func New(avg uint64) (*Chunker, error)

New returns a Chunker with the given average chunk size; 0 means DefaultAvg (4 MiB). The average must be a power of two of at least 4×the window (the break mask arithmetic depends on it).

func (*Chunker) Reset

func (c *Chunker) Reset()

Reset discards the current chunk state.

func (*Chunker) Scan

func (c *Chunker) Scan(data []byte) int

Scan consumes data and returns the position just past the next chunk boundary, or 0 if data ends without one. State carries across calls, so a stream may be fed in arbitrary segments; after a non-zero return, continue scanning from that position.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL