From c686992e850183a79b7f4619b7979ffcfb1c223a Mon Sep 17 00:00:00 2001 From: PotatoMaaan <60669730+PotatoMaaan@users.noreply.github.com> Date: Mon, 26 Sep 2022 02:47:09 +0200 Subject: [PATCH] backups: add an option to change gzip compression level (#128) --- config/config.go | 9 +++++++++ server/filesystem/archive.go | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 4efb7b9..7f504d0 100644 --- a/config/config.go +++ b/config/config.go @@ -219,6 +219,15 @@ type Backups struct { // // Defaults to 0 (unlimited) WriteLimit int `default:"0" yaml:"write_limit"` + + // CompressionLevel determines how much backups created by wings should be compressed. + // + // "none" -> no compression will be applied + // "best_speed" -> uses gzip level 1 for fast speed + // "best_compression" -> uses gzip level 9 for minimal disk space useage + // + // Defaults to "best_speed" (level 1) + CompressionLevel string `default:"best_speed" yaml:"compression_level"` } type Transfers struct { diff --git a/server/filesystem/archive.go b/server/filesystem/archive.go index 49dffb5..668d8bd 100644 --- a/server/filesystem/archive.go +++ b/server/filesystem/archive.go @@ -62,8 +62,21 @@ func (a *Archive) Create(dst string) error { writer = f } + // The default compression level is BestSpeed + var cl = pgzip.BestSpeed + + // Choose which compression level to use based on the compression_level configuration option + switch config.Get().System.Backups.CompressionLevel { + case "none": + cl = pgzip.NoCompression + case "best_speed": + cl = pgzip.BestSpeed + case "best_compression": + cl = pgzip.BestCompression + } + // Create a new gzip writer around the file. - gw, _ := pgzip.NewWriterLevel(writer, pgzip.BestSpeed) + gw, _ := pgzip.NewWriterLevel(writer, cl) _ = gw.SetConcurrency(1<<20, 1) defer gw.Close()