diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-20 11:06:47 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-20 11:44:32 +0200 |
commit | 81f191fdcd347df0b7ae52e061c9ab39e88bdbb1 (patch) | |
tree | 489fff15739ba095f75223b460bec48d034c06a6 /repo.go | |
parent | 129032a13d19d500011fe23bcdd232b87eeb9b2f (diff) | |
download | dna-backup-81f191fdcd347df0b7ae52e061c9ab39e88bdbb1.tar.gz dna-backup-81f191fdcd347df0b7ae52e061c9ab39e88bdbb1.zip |
store fileList compressed
for now using zlib on a 556Mo dir:
files: 1469447 o -> 207289 o
size divided by 7
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 37 |
1 files changed, 25 insertions, 12 deletions
@@ -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 } |