Documentation ¶
Overview ¶
Package fastcdc implements the FastCDC algorithm for content-defined chunking.
Example ¶
package main import ( "fmt" "os" "codeberg.org/mhofmann/fastcdc" ) func main() { f, err := os.Open("testdata/testfile.bin") if err != nil { panic(err) } defer f.Close() var nChunks, nBytes int chunker := fastcdc.NewRefChunker(f) for chunker.Next() { chunk := chunker.Chunk() nBytes += len(chunk) nChunks++ } if err = chunker.Err(); err != nil { panic(err) } fmt.Printf("read %d chunks with %d bytes total\n", nChunks, nBytes) }
Output: read 14 chunks with 130873 bytes total
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrParam = errors.New("invalid parameter")
ErrParam is returned by NewChunker when one or more of the size parameters are invalid.
Functions ¶
This section is empty.
Types ¶
type Chunker ¶
type Chunker struct {
// contains filtered or unexported fields
}
Chunker wraps an io.Reader and returns data in chunks of bytes. Successive calls to Next will split the input data into variable sized chunks according to the FastCDC algorithm. The Chunk method returns the current chunk. The process stops at EOF or the first I/O error. Use the Err method to see if a non-EOF error occurred.
func NewChunker ¶
NewChunker returns a new chunker that wraps r and uses the given parameters for FastCDC. minSize is the minimum size, in bytes, of chunks, that the Chunker should return. Likewise, avgSize and maxSize set the average (expected) and maximum size of chunks in bytes. avgSize must be a power of two and the parameters must be ordered so that 1 <= minSize <= avgSize <= maxSize.
func NewRefChunker ¶
NewRefChunker returns a new chunker that wraps r and uses the reference parameters for FastCDC. The minimal, maximal and average sizes of chunks returned by this chunker are 2KB, 64KB and 8KB respectively.
func (*Chunker) Chunk ¶
Chunk returns the most recent chunk of data generated by a call to Next. The underlying array points to data that might be overwritten by subsequent calls to Next.
func (*Chunker) Next ¶
Next retrieves the next chunk of data, which will then be available through the Chunk method. It returns false when the chunking process stops, either by reaching the end of the input stream or an error. After Next returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil.