registered a custom Deflate compressor to speedup the backups generation

This commit is contained in:
Gani Georgiev
2023-09-01 13:46:51 +03:00
parent 78e70bd52b
commit 322508f6d1
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -2,6 +2,7 @@ package archive
import (
"archive/zip"
"compress/flate"
"io"
"io/fs"
"os"
@@ -27,6 +28,11 @@ func Create(src string, dest string, skipPaths ...string) error {
zw := zip.NewWriter(zf)
defer zw.Close()
// register a custom Deflate compressor
zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
return flate.NewWriter(out, flate.BestSpeed)
})
if err := zipAddFS(zw, os.DirFS(src), skipPaths...); err != nil {
// try to cleanup at least the created zip file
os.Remove(dest)