jc

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package jc implements the JC (Jump Condition) content-defined chunking algorithm.

This file is from https://raw.githubusercontent.com/PlakarKorp/go-cdc-chunkers/423839/chunkers/jc/jc.go and is licensed under the ISC license, shown above.

It has been modified to have a simplified API.

Index

Constants

View Source
const (
	DefaultMinSize    uint64 = 2 * 1024  // 2KB
	DefaultMaxSize    uint64 = 64 * 1024 // 64KB
	DefaultTargetSize uint64 = 8 * 1024  // 8KB
)

Default chunking parameters

Variables

View Source
var (
	ErrTargetSize = errors.New("TargetSize is required and must be 64B <= TargetSize <= 1GB")
	ErrMinSize    = errors.New("MinSize is required and must be 64B <= MinSize <= 1GB && MinSize < TargetSize")
	ErrMaxSize    = errors.New("MaxSize is required and must be 64B <= MaxSize <= 1GB && MaxSize > TargetSize")
)

Functions

func Algorithm

func Algorithm(data []byte, n int, G []uint64, maskC, maskJ uint64, jumpLength, minSize, maxSize, targetSize int) int

Algorithm implements the JC algorithm as a top-level function.

Types

type Chunk

type Chunk struct {
	// Start is the absolute position in the stream where this chunk begins
	Start uint64
	// Length is the length of the chunk
	Length int
	// Data contains the actual chunk data
	Data []byte
}

Chunk represents a chunk of data with its position and data.

type Chunker

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

Chunker wraps JC to provide streaming chunking functionality.

func NewChunker

func NewChunker(reader io.Reader) (*Chunker, error)

NewChunker creates a new streaming chunker with the default parameters.

func NewChunkerWithOptions

func NewChunkerWithOptions(reader io.Reader, minSize, maxSize, targetSize uint64, key []byte) (*Chunker, error)

NewChunkerWithOptions creates a new streaming chunker with the given options.

func (*Chunker) Next

func (c *Chunker) Next(data []byte) (Chunk, error)

Next returns the position and length of the next chunk of data. If an error occurs while reading, the error is returned. Afterwards, the state of the current chunk is undefined. When the last chunk has been returned, all subsequent calls yield an io.EOF error.

func (*Chunker) Reset

func (c *Chunker) Reset()

Reset clears the internal buffers and resets the chunker state to release memory. The chunker can be reused after calling Reset with the same reader and options.

type JC

type JC struct {
	G [gLen]uint64
	// contains filtered or unexported fields
}

func NewJC

func NewJC() (*JC, error)

NewJC constructs the JC with the default parameters.

func NewWithOptions

func NewWithOptions(minSize, maxSize, targetSize uint64, key []byte) (*JC, error)

NewWithOptions constructs the JC with the given options.

func (*JC) Algorithm

func (c *JC) Algorithm(data []byte, n int) int

Algorithm implements the JC algorithm.

Jump to

Keyboard shortcuts

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