diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-07 14:59:13 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-07 14:59:13 +0200 |
commit | bff88ab3a6cfd38de9d610fc6f5958ca3d93937e (patch) | |
tree | 7a813b90706f2221da049357e35e74b60d096248 /repo.go | |
parent | 1e5d2641fe31bad543065fdf82887614ceb3b3ad (diff) | |
download | dna-backup-bff88ab3a6cfd38de9d610fc6f5958ca3d93937e.tar.gz dna-backup-bff88ab3a6cfd38de9d610fc6f5958ca3d93937e.zip |
fix matchStream did not store first chunk
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -394,15 +394,19 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk { var chunks []Chunk var prev *TempChunk var last uint64 + var err error bufStream := bufio.NewReaderSize(stream, r.chunkSize*2) - buff := make([]byte, 0, r.chunkSize*2) - n, err := io.ReadFull(stream, buff[:r.chunkSize]) - if n < r.chunkSize { - chunks = append(chunks, NewTempChunk(buff[:n])) - return chunks + buff := make([]byte, r.chunkSize, r.chunkSize*2) + if n, err := io.ReadFull(stream, buff); n < r.chunkSize { + if err == io.EOF { + chunks = append(chunks, NewTempChunk(buff[:n])) + return chunks + } else { + log.Panicf("Error Read only %d bytes with error '%s'\n", n, err) + } } hasher := rabinkarp64.NewFromPol(r.pol) - hasher.Write(buff[:n]) + hasher.Write(buff) for err != io.EOF { h := hasher.Sum64() chunkId, exists := r.fingerprints[h] @@ -422,8 +426,10 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk { buff = make([]byte, 0, r.chunkSize*2) for i := 0; i < r.chunkSize && err == nil; i++ { b, err = bufStream.ReadByte() - hasher.Roll(b) - buff = append(buff, b) + if err != io.EOF { + hasher.Roll(b) + buff = append(buff, b) + } } continue } @@ -434,8 +440,8 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk { } prev = NewTempChunk(buff[:r.chunkSize]) tmp := buff[r.chunkSize:] - buff = make([]byte, 0, r.chunkSize*2) - buff = append(buff, tmp...) + buff = make([]byte, r.chunkSize, r.chunkSize*2) + copy(buff, tmp) } b, err = bufStream.ReadByte() if err != io.EOF { |