From d9703a9daa05f30e77bb99393eab8a0d40e788e4 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Thu, 2 Sep 2021 17:48:23 +0200 Subject: hash and store chunks left by matchStream --- chunk.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'chunk.go') diff --git a/chunk.go b/chunk.go index abcdf1c..6c76d5e 100644 --- a/chunk.go +++ b/chunk.go @@ -20,11 +20,16 @@ type Chunk interface { Len() int } -type StoredChunk interface { +type IdentifiedChunk interface { Chunk Id() *ChunkId } +type BufferedChunk interface { + Chunk + Bytes() []byte +} + type ChunkId struct { Ver int Idx uint64 @@ -65,25 +70,29 @@ func (c *LoadedChunk) Len() int { return len(c.value) } -func NewChunkFile(repo *Repo, id *ChunkId) *ChunkFile { - return &ChunkFile{repo: repo, id: id} +func (c *LoadedChunk) Bytes() []byte { + return c.value +} + +func NewStoredFile(repo *Repo, id *ChunkId) *StoredChunk { + return &StoredChunk{repo: repo, id: id} } -type ChunkFile struct { +type StoredChunk struct { repo *Repo id *ChunkId } -func (c *ChunkFile) Id() *ChunkId { +func (c *StoredChunk) Id() *ChunkId { return c.id } -func (c *ChunkFile) Reader() ChunkReader { +func (c *StoredChunk) Reader() ChunkReader { // log.Printf("Chunk %d: Reading from file\n", c.id) return c.id.Reader(c.repo) } -func (c *ChunkFile) Len() int { +func (c *StoredChunk) Len() int { path := c.id.Path(c.repo.path) info, err := os.Stat(path) if err != nil { -- cgit v1.2.3