From 81f191fdcd347df0b7ae52e061c9ab39e88bdbb1 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 20 Sep 2021 11:06:47 +0200 Subject: store fileList compressed for now using zlib on a 556Mo dir: files: 1469447 o -> 207289 o size divided by 7 --- repo.go | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'repo.go') 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 } -- cgit v1.2.3