aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-08-31 17:45:07 +0200
committern-peugnet <n.peugnet@free.fr>2021-08-31 17:45:07 +0200
commite207ff4759e9e2aba9b4938f54ed2f31d362f7ee (patch)
treef6ef11b0f40e8563878dab7b14ef3ec743e6f9c9
parent504fe3db47c058807b656a8e63bb27c12420f268 (diff)
downloaddna-backup-e207ff4759e9e2aba9b4938f54ed2f31d362f7ee.tar.gz
dna-backup-e207ff4759e9e2aba9b4938f54ed2f31d362f7ee.zip
fix matchStream if first chunk is not matched
-rw-r--r--repo.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/repo.go b/repo.go
index d32d437..a987dc6 100644
--- a/repo.go
+++ b/repo.go
@@ -265,24 +265,18 @@ func findSimilarChunk(chunk Chunk, sketches SketchMap) (*ChunkId, bool) {
return similarChunk, similarChunk != nil
}
-func readChunk(stream io.Reader) ([]byte, error) {
- buff := make([]byte, chunkSize)
- _, err := io.ReadFull(stream, buff)
- return buff, err
-}
-
func (r *Repo) matchStream(stream io.Reader, fingerprints FingerprintMap) []Chunk {
var b byte
var chunks []Chunk
bufStream := bufio.NewReaderSize(stream, chunkSize)
- buff, err := readChunk(bufStream)
- if err == io.EOF {
- chunks = append(chunks, NewTempChunk(buff))
+ buff := make([]byte, 0, chunkSize*2)
+ n, err := io.ReadFull(stream, buff[:chunkSize])
+ if n < chunkSize {
+ chunks = append(chunks, NewTempChunk(buff[:n]))
return chunks
}
hasher := rabinkarp64.New()
- hasher.Write(buff)
- buff = make([]byte, 0, chunkSize*2)
+ hasher.Write(buff[:n])
for err != io.EOF {
h := hasher.Sum64()
chunkId, exists := fingerprints[h]
@@ -297,8 +291,8 @@ func (r *Repo) matchStream(stream io.Reader, fingerprints FingerprintMap) []Chun
buff = make([]byte, 0, chunkSize*2)
for i := 0; i < chunkSize && err == nil; i++ {
b, err = bufStream.ReadByte()
- buff = append(buff, b)
hasher.Roll(b)
+ buff = append(buff, b)
}
continue
}