chunker

package
v1.124.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chunker cuts byte streams into content-defined chunks with a FastCDC-style normalised Gear hash.

A Profile fixes how bytes are cut, so every agent cutting with the same profile cuts identical bytes identically. A profile's target is a power of two 2^k from 64 KiB to 1 MiB; chunks are cut from a quarter of it to four times it. The gear table entry for byte value v is the first eight bytes, big-endian, of SHA-256 of the single byte v. The masks have k+1 (below the target) and k-1 (above it) one bits at every third position from the top of the 64-bit fingerprint.

Index

Constants

View Source
const (
	// DefaultTarget is the target chunk size of the zero Profile.
	DefaultTarget = 64 << 10
	// MaxTarget is the largest target a Profile takes.
	MaxTarget = 1 << 20
	// SmallestChunk is the smallest chunk any profile cuts before the end
	// of a stream.
	SmallestChunk = DefaultTarget / 4
	// LargestChunk is the largest chunk any profile cuts.
	LargestChunk = 4 * MaxTarget
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FastCDC

type FastCDC struct {
	Profile Profile
	// contains filtered or unexported fields
}

FastCDC holds the fingerprint of the chunk currently being scanned with its Profile.

func (*FastCDC) Reset

func (c *FastCDC) Reset()

Reset forgets the current chunk, for use when the stream ends mid-chunk.

func (*FastCDC) Scan

func (c *FastCDC) Scan(chunk []byte, scanned int) int

Scan looks at chunk[scanned:], where chunk holds the bytes of the current chunk collected so far, and returns the chunk length if a cut point was found, or 0 if more bytes are needed. A cut resets the fingerprint.

type Profile added in v1.124.0

type Profile uint32

Profile is how a store cuts content: its target chunk size in bytes. The zero Profile cuts with DefaultTarget.

func NewProfile added in v1.124.0

func NewProfile(target uint32) (Profile, error)

NewProfile returns the profile of target, a power of two from DefaultTarget to MaxTarget; 0 is the default.

func (Profile) Max added in v1.124.0

func (p Profile) Max() int

Max is the largest chunk; a cut is forced there.

func (Profile) Min added in v1.124.0

func (p Profile) Min() int

Min is the smallest chunk cut before the end of a stream.

func (Profile) Split added in v1.124.0

func (p Profile) Split(data []byte) []int

Split cuts a whole buffer and returns the chunk lengths in order.

func (Profile) Target added in v1.124.0

func (p Profile) Target() int

Target is the size chunks are cut around.

Jump to

Keyboard shortcuts

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