From 72ec5a391646014531727fb3a71987d87b8a6933 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Tue, 31 Aug 2021 18:08:14 +0200 Subject: split extractTempChunks into 2 funcs --- repo.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'repo.go') diff --git a/repo.go b/repo.go index a987dc6..ea27fb4 100644 --- a/repo.go +++ b/repo.go @@ -321,10 +321,10 @@ func (r *Repo) matchStream(stream io.Reader, fingerprints FingerprintMap) []Chun return chunks } -// extractTempChunks extracts temporary chunks from an array of chunks. +// mergeTempChunks joins temporary partial chunks from an array of chunks if possible. // If a chunk is smaller than the size required to calculate a super-feature, // it is then appended to the previous consecutive temporary chunk if it exists. -func extractTempChunks(chunks []Chunk) (ret []Chunk) { +func mergeTempChunks(chunks []Chunk) (ret []Chunk) { var prev *TempChunk var curr *TempChunk for _, c := range chunks { @@ -335,6 +335,7 @@ func extractTempChunks(chunks []Chunk) (ret []Chunk) { } else if curr != nil { ret = append(ret, curr) } + ret = append(ret, c) curr = nil prev = nil } else { @@ -351,6 +352,16 @@ func extractTempChunks(chunks []Chunk) (ret []Chunk) { return } +func extractTempChunks(chunks []Chunk) (ret []*TempChunk) { + for _, c := range chunks { + tmp, isTmp := c.(*TempChunk) + if isTmp { + ret = append(ret, tmp) + } + } + return +} + func writeFile(filePath string, object interface{}) error { file, err := os.Create(filePath) if err == nil { -- cgit v1.2.3