mirror of
https://github.com/restic/restic.git
synced 2026-08-21 13:03:25 +00:00
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:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user