aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md2
-rw-r--r--repo.go39
-rw-r--r--testdata/repo_8k/00000/recipebin6570 -> 2532 bytes
-rw-r--r--testdata/repo_8k_zlib/00000/recipebin6570 -> 2532 bytes
4 files changed, 27 insertions, 14 deletions
diff --git a/TODO.md b/TODO.md
index acab4c2..9332c3a 100644
--- a/TODO.md
+++ b/TODO.md
@@ -45,7 +45,7 @@ reunion 7/09
------------
- [ ] save recipe consecutive chunks as extents
- [ ] store recipe and files incrementally
-- [ ] compress recipe
+- [x] compress recipe
- [x] compress file list
- [ ] make size comparison between recipe and chunks with some datasets
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)
}
diff --git a/testdata/repo_8k/00000/recipe b/testdata/repo_8k/00000/recipe
index 9a3962c..7532ee9 100644
--- a/testdata/repo_8k/00000/recipe
+++ b/testdata/repo_8k/00000/recipe
Binary files differ
diff --git a/testdata/repo_8k_zlib/00000/recipe b/testdata/repo_8k_zlib/00000/recipe
index 9a3962c..7532ee9 100644
--- a/testdata/repo_8k_zlib/00000/recipe
+++ b/testdata/repo_8k_zlib/00000/recipe
Binary files differ