diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-10 14:37:32 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-10 14:37:32 +0200 |
commit | 13e45db0878bc2dc36ad4578c0758dd05879cded (patch) | |
tree | 942d332e3b513cd25f869f3900d8f9ba21d3f1dd /repo.go | |
parent | bea4f87f1e4528630d326699a9c7fd6133ee7806 (diff) | |
download | dna-backup-13e45db0878bc2dc36ad4578c0758dd05879cded.tar.gz dna-backup-13e45db0878bc2dc36ad4578c0758dd05879cded.zip |
use moare the reader interface
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -313,16 +313,18 @@ func (r *Repo) chunkMinLen() int { func (r *Repo) hashChunks(chunks <-chan IdentifiedChunk) { hasher := rabinkarp64.NewFromPol(r.pol) for c := range chunks { - r.hashAndStoreChunk(c, hasher) + r.hashAndStoreChunk(c.GetId(), c.Reader(), hasher) } } -func (r *Repo) hashAndStoreChunk(chunk IdentifiedChunk, hasher hash.Hash64) { +func (r *Repo) hashAndStoreChunk(id *ChunkId, reader io.Reader, hasher hash.Hash64) { + var chunk bytes.Buffer hasher.Reset() - io.Copy(hasher, chunk.Reader()) + reader = io.TeeReader(reader, &chunk) + io.Copy(hasher, reader) fingerprint := hasher.Sum64() - sketch, _ := sketch.SketchChunk(chunk.Reader(), r.pol, r.chunkSize, r.sketchWSize, r.sketchSfCount, r.sketchFCount) - r.storeChunkId(chunk.GetId(), fingerprint, sketch) + sketch, _ := sketch.SketchChunk(&chunk, r.pol, r.chunkSize, r.sketchWSize, r.sketchSfCount, r.sketchFCount) + r.storeChunkId(id, fingerprint, sketch) } func (r *Repo) storeChunkId(id *ChunkId, fingerprint uint64, sketch []uint64) { @@ -397,10 +399,9 @@ func (r *Repo) encodeTempChunk(temp BufferedChunk, version int, last *uint64) (c if chunk.Len() == r.chunkSize { id := &ChunkId{Ver: version, Idx: *last} *last++ - ic := NewLoadedChunk(id, temp.Bytes()) hasher := rabinkarp64.NewFromPol(r.pol) - r.hashAndStoreChunk(ic, hasher) - r.StoreChunkContent(id, ic.Reader()) + r.hashAndStoreChunk(id, temp.Reader(), hasher) + r.StoreChunkContent(id, temp.Reader()) log.Println("Add new chunk", id) return NewStoredChunk(r, id), false } |