repository: add ChunkerFactory and decouple archiver from chunker

Introduce restic.Chunker and ChunkerFactory interfaces with a
repository-backed implementation. The archiver obtains chunkers via
ChunkerFactory() from the repository.
This commit is contained in:
Michael Eischer
2026-06-27 22:13:41 +02:00
parent 70a45791b2
commit ccb828e87b
6 changed files with 75 additions and 19 deletions
+39
View File
@@ -0,0 +1,39 @@
package repository
import (
"github.com/restic/chunker"
"github.com/restic/restic/internal/restic"
)
type baseChunker struct {
bc *chunker.BaseChunker
pol chunker.Pol
}
func (c *baseChunker) Reset() {
c.bc.Reset(c.pol)
}
func (c *baseChunker) NextSplitPoint(buf []byte) int {
return c.bc.NextSplitPoint(buf)
}
type chunkerFactory struct {
pol chunker.Pol
}
func newChunkerFactory(pol chunker.Pol) *chunkerFactory {
return &chunkerFactory{pol: pol}
}
func (f *chunkerFactory) NewChunker() restic.Chunker {
return &baseChunker{bc: chunker.NewBase(f.pol), pol: f.pol}
}
func (f *chunkerFactory) MaxChunkSize() int {
return chunker.MaxSize
}
func (r *Repository) ChunkerFactory() restic.ChunkerFactory {
return newChunkerFactory(r.Config().ChunkerPolynomial)
}