diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-08-31 17:45:07 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-08-31 17:45:07 +0200 |
commit | e207ff4759e9e2aba9b4938f54ed2f31d362f7ee (patch) | |
tree | f6ef11b0f40e8563878dab7b14ef3ec743e6f9c9 /repo.go | |
parent | 504fe3db47c058807b656a8e63bb27c12420f268 (diff) | |
download | dna-backup-e207ff4759e9e2aba9b4938f54ed2f31d362f7ee.tar.gz dna-backup-e207ff4759e9e2aba9b4938f54ed2f31d362f7ee.zip |
fix matchStream if first chunk is not matched
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -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 } |