Skip to content

Commit

Permalink
feat: use maximum compression for gzip and zip archives (#1416)
Browse files Browse the repository at this point in the history
* feat: use maximum compression for gzip and zip archives

* fix: add comment for skipping error check

Co-authored-by: John Taylor <ec2-user@ip-172-31-29-117.ap-south-1.compute.internal>
  • Loading branch information
jftuga and John Taylor committed Apr 1, 2020
1 parent 375109a commit e2ef520
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/archive/gzip/gzip.go
Expand Up @@ -21,7 +21,8 @@ func (a Archive) Close() error {

// New gz archive
func New(target io.Writer) Archive {
gw := gzip.NewWriter(target)
// the error will be nil since the compression level is valid
gw, _ := gzip.NewWriterLevel(target, gzip.BestCompression)
return Archive{
gw: gw,
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/archive/targz/targz.go
Expand Up @@ -25,7 +25,8 @@ func (a Archive) Close() error {

// New tar.gz archive
func New(target io.Writer) Archive {
gw := gzip.NewWriter(target)
// the error will be nil since the compression level is valid
gw, _ := gzip.NewWriterLevel(target, gzip.BestCompression)
tw := tar.NewWriter(gw)
return Archive{
gw: gw,
Expand Down
7 changes: 6 additions & 1 deletion pkg/archive/zip/zip.go
Expand Up @@ -4,6 +4,7 @@ package zip

import (
"archive/zip"
"compress/flate"
"io"
"os"
)
Expand All @@ -20,8 +21,12 @@ func (a Archive) Close() error {

// New zip archive
func New(target io.Writer) Archive {
compressor := zip.NewWriter(target)
compressor.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
return flate.NewWriter(out, flate.BestCompression)
})
return Archive{
z: zip.NewWriter(target),
z: compressor,
}
}

Expand Down

0 comments on commit e2ef520

Please sign in to comment.