From 656a2c10b177e7fafc0b4bbddf3c634c642a2221 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 6 Sep 2021 18:19:43 +0200 Subject: fixes: chunk id starts from 0 & nil check --- repo.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'repo.go') diff --git a/repo.go b/repo.go index cd5178b..8bd069a 100644 --- a/repo.go +++ b/repo.go @@ -36,6 +36,7 @@ import ( "os" "path" "path/filepath" + "reflect" "github.com/chmduquesne/rollinghash/rabinkarp64" ) @@ -219,6 +220,7 @@ func storeChunks(dest string, chunks <-chan []byte) { } } +// TODO: use atoi for chunkid func (r *Repo) loadChunks(versions []string, chunks chan<- IdentifiedChunk) { for i, v := range versions { p := path.Join(v, chunksName) @@ -336,8 +338,8 @@ func (r *Repo) encodeTempChunk(temp BufferedChunk, version int, last *uint64) (c return } if chunk.Len() == r.chunkSize { - *last++ id := &ChunkId{Ver: version, Idx: *last} + *last++ ic := NewLoadedChunk(id, temp.Bytes()) hasher := rabinkarp64.NewFromPol(r.pol) r.hashAndStoreChunk(ic, hasher) @@ -349,7 +351,7 @@ func (r *Repo) encodeTempChunk(temp BufferedChunk, version int, last *uint64) (c } func (r *Repo) encodeTempChunks(prev BufferedChunk, curr BufferedChunk, version int, last *uint64) []Chunk { - if prev == nil { + if reflect.ValueOf(prev).IsNil() { c, _ := r.encodeTempChunk(curr, version, last) return []Chunk{c} } else if curr.Len() < r.chunkMinLen() { @@ -371,7 +373,7 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk { var chunks []Chunk var prev *TempChunk var last uint64 - bufStream := bufio.NewReaderSize(stream, r.chunkSize) + 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 { -- cgit v1.2.3