aboutsummaryrefslogtreecommitdiff
path: root/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'repo.go')
-rw-r--r--repo.go37
1 files changed, 25 insertions, 12 deletions
diff --git a/repo.go b/repo.go
index 3dab2b3..108ef5f 100644
--- a/repo.go
+++ b/repo.go
@@ -73,8 +73,8 @@ type Repo struct {
fingerprints FingerprintMap
sketches SketchMap
chunkCache cache.Cacher
- chunkReadWrapper func(r io.Reader) (io.ReadCloser, error)
- chunkWriteWrapper func(w io.Writer) io.WriteCloser
+ chunkReadWrapper utils.ReadWrapper
+ chunkWriteWrapper utils.WriteWrapper
}
type chunkHashes struct {
@@ -240,41 +240,54 @@ func concatFiles(files []File, stream io.WriteCloser) {
stream.Close()
}
-func storeBasicStruct(dest string, obj interface{}) {
+func storeBasicStruct(dest string, wrapper utils.WriteWrapper, obj interface{}) {
file, err := os.Create(dest)
- if err == nil {
- encoder := gob.NewEncoder(file)
- err = encoder.Encode(obj)
+ if err != nil {
+ logger.Panic(err)
}
+ out := wrapper(file)
+ encoder := gob.NewEncoder(out)
+ err = encoder.Encode(obj)
if err != nil {
logger.Panic(err)
}
+ if err = out.Close(); err != nil {
+ logger.Panic(err)
+ }
if err = file.Close(); err != nil {
logger.Panic(err)
}
}
-func loadBasicStruct(path string, obj interface{}) {
+func loadBasicStruct(path string, wrapper utils.ReadWrapper, obj interface{}) {
file, err := os.Open(path)
- if err == nil {
- decoder := gob.NewDecoder(file)
- err = decoder.Decode(obj)
+ if err != nil {
+ logger.Panic(err)
}
+ in, err := wrapper(file)
if err != nil {
logger.Panic(err)
}
+ decoder := gob.NewDecoder(in)
+ err = decoder.Decode(obj)
+ if err != nil {
+ logger.Panic(err)
+ }
+ if err = in.Close(); err != nil {
+ logger.Panic(err)
+ }
if err = file.Close(); err != nil {
logger.Panic(err)
}
}
func storeFileList(dest string, files []File) {
- storeBasicStruct(dest, files)
+ storeBasicStruct(dest, utils.ZlibWriter, files)
}
func loadFileList(path string) []File {
var files []File
- loadBasicStruct(path, &files)
+ loadBasicStruct(path, utils.ZlibReader, &files)
return files
}