diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-06 16:37:50 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-06 16:37:50 +0200 |
commit | b31f22ff61b69a0cb3e0a9d7955133b5304f4ff7 (patch) | |
tree | f188b6f15f54457ecc03089bb74385c27fcc8593 /chunk.go | |
parent | d9703a9daa05f30e77bb99393eab8a0d40e788e4 (diff) | |
download | dna-backup-b31f22ff61b69a0cb3e0a9d7955133b5304f4ff7.tar.gz dna-backup-b31f22ff61b69a0cb3e0a9d7955133b5304f4ff7.zip |
calculate features concurently
Diffstat (limited to 'chunk.go')
-rw-r--r-- | chunk.go | 22 |
1 files changed, 8 insertions, 14 deletions
@@ -1,7 +1,6 @@ package main import ( - "bufio" "bytes" "fmt" "io" @@ -10,13 +9,8 @@ import ( "path" ) -type ChunkReader interface { - io.Reader - io.ByteReader -} - type Chunk interface { - Reader() ChunkReader + Reader() io.ReadSeeker Len() int } @@ -39,13 +33,13 @@ func (i *ChunkId) Path(repo string) string { return path.Join(repo, fmt.Sprintf(versionFmt, i.Ver), chunksName, fmt.Sprintf(chunkIdFmt, i.Idx)) } -func (i *ChunkId) Reader(repo *Repo) ChunkReader { +func (i *ChunkId) Reader(repo *Repo) io.ReadSeeker { path := i.Path(repo.path) f, err := os.Open(path) if err != nil { log.Println("Cannot open chunk: ", path) } - return bufio.NewReaderSize(f, repo.chunkSize) + return f } func NewLoadedChunk(id *ChunkId, value []byte) *LoadedChunk { @@ -61,7 +55,7 @@ func (c *LoadedChunk) Id() *ChunkId { return c.id } -func (c *LoadedChunk) Reader() ChunkReader { +func (c *LoadedChunk) Reader() io.ReadSeeker { // log.Printf("Chunk %d: Reading from in-memory value\n", c.id) return bytes.NewReader(c.value) } @@ -87,7 +81,7 @@ func (c *StoredChunk) Id() *ChunkId { return c.id } -func (c *StoredChunk) Reader() ChunkReader { +func (c *StoredChunk) Reader() io.ReadSeeker { // log.Printf("Chunk %d: Reading from file\n", c.id) return c.id.Reader(c.repo) } @@ -109,7 +103,7 @@ type TempChunk struct { value []byte } -func (c *TempChunk) Reader() ChunkReader { +func (c *TempChunk) Reader() io.ReadSeeker { return bytes.NewReader(c.value) } @@ -136,10 +130,10 @@ type DeltaChunk struct { size int } -func (c *DeltaChunk) Reader() ChunkReader { +func (c *DeltaChunk) Reader() io.ReadSeeker { var buff bytes.Buffer c.repo.Patcher().Patch(c.source.Reader(c.repo), &buff, bytes.NewReader(c.patch)) - return &buff + return bytes.NewReader(buff.Bytes()) } // TODO: Maybe return the size of the patch instead ? |