aboutsummaryrefslogtreecommitdiff
path: root/repo.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-20 14:52:05 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-20 14:52:05 +0200
commita20f4f17708356150eb8335be1d0f5a767416c1d (patch)
tree3884d6b0c61ac5db8b7ffd994dee8d768c5799d6 /repo.go
parent540426db79b6e49b79d58aef99ffee5005dc987d (diff)
downloaddna-backup-a20f4f17708356150eb8335be1d0f5a767416c1d.tar.gz
dna-backup-a20f4f17708356150eb8335be1d0f5a767416c1d.zip
store recipe compressed
for now using zlib on a 556Mo dir: recipe: 11668558 o -> 5540831 o size divided by 2
Diffstat (limited to 'repo.go')
-rw-r--r--repo.go39
1 files changed, 26 insertions, 13 deletions
diff --git a/repo.go b/repo.go
index 36adb81..1e0f141 100644
--- a/repo.go
+++ b/repo.go
@@ -652,17 +652,22 @@ func (r *Repo) restoreStream(stream io.WriteCloser, recipe []Chunk) {
func storeRecipe(dest string, recipe []Chunk) {
file, err := os.Create(dest)
- if err == nil {
- encoder := gob.NewEncoder(file)
- for _, c := range recipe {
- if err = encoder.Encode(&c); err != nil {
- logger.Panic(err)
- }
+ if err != nil {
+ logger.Panic(err)
+ }
+ out := utils.ZlibWriter(file)
+ encoder := gob.NewEncoder(out)
+ for _, c := range recipe {
+ if err = encoder.Encode(&c); err != nil {
+ logger.Panic(err)
}
}
if err != nil {
logger.Panic(err)
}
+ if err = out.Close(); err != nil {
+ logger.Panic(err)
+ }
if err = file.Close(); err != nil {
logger.Panic(err)
}
@@ -671,18 +676,26 @@ func storeRecipe(dest string, recipe []Chunk) {
func loadRecipe(path string) []Chunk {
var recipe []Chunk
file, err := os.Open(path)
- if err == nil {
- decoder := gob.NewDecoder(file)
- for i := 0; err == nil; i++ {
- var c Chunk
- if err = decoder.Decode(&c); err == nil {
- recipe = append(recipe, c)
- }
+ if err != nil && err != io.EOF {
+ logger.Panic(err)
+ }
+ in, err := utils.ZlibReader(file)
+ if err != nil {
+ logger.Panic(err)
+ }
+ decoder := gob.NewDecoder(in)
+ for i := 0; err == nil; i++ {
+ var c Chunk
+ if err = decoder.Decode(&c); err == nil {
+ recipe = append(recipe, c)
}
}
if err != nil && err != io.EOF {
logger.Panic(err)
}
+ if err = in.Close(); err != nil {
+ logger.Panic(err)
+ }
if err = file.Close(); err != nil {
logger.Panic(err)
}