From cce3365003dba7c3ac2905f71aa284caf63a1c78 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Wed, 22 Sep 2021 19:50:41 +0200 Subject: fix for stream smaller than chunkSize --- repo.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'repo.go') diff --git a/repo.go b/repo.go index ac7fe3e..f36bb65 100644 --- a/repo.go +++ b/repo.go @@ -595,9 +595,13 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk { var err error bufStream := bufio.NewReaderSize(stream, r.chunkSize*2) buff := make([]byte, r.chunkSize, r.chunkSize*2) + storeQueue := make(chan chunkData, 10) + storeEnd := make(chan bool) + go r.storageWorker(version, storeQueue, storeEnd) if n, err := io.ReadFull(stream, buff); n < r.chunkSize { - if err == io.EOF { - chunks = append(chunks, NewTempChunk(buff[:n])) + if err == io.ErrUnexpectedEOF { + c, _ := r.encodeTempChunk(NewTempChunk(buff[:n]), version, &last, storeQueue) + chunks = append(chunks, c) return chunks } else { logger.Panicf("matching stream, read only %d bytes with error '%s'", n, err) @@ -605,9 +609,6 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk { } hasher := rabinkarp64.NewFromPol(r.pol) hasher.Write(buff) - storeQueue := make(chan chunkData, 10) - storeEnd := make(chan bool) - go r.storageWorker(version, storeQueue, storeEnd) for err != io.EOF { h := hasher.Sum64() chunkId, exists := r.fingerprints[h] -- cgit v1.2.3