aboutsummaryrefslogtreecommitdiff
path: root/chunk.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-02 17:48:23 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-02 17:48:23 +0200
commitd9703a9daa05f30e77bb99393eab8a0d40e788e4 (patch)
tree813f08947ad0958dd3c42f7db62bd39fe6430bbf /chunk.go
parent2a048d5d8b2b25326685ba53fc390781ba96deed (diff)
downloaddna-backup-d9703a9daa05f30e77bb99393eab8a0d40e788e4.tar.gz
dna-backup-d9703a9daa05f30e77bb99393eab8a0d40e788e4.zip
hash and store chunks left by matchStream
Diffstat (limited to 'chunk.go')
-rw-r--r--chunk.go23
1 files changed, 16 insertions, 7 deletions
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 {