about summary refs log tree commit diff
path: root/tools/nixery/server/builder/archive.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-10-11T00·28+0100
committerVincent Ambo <github@tazj.in>2019-10-11T11·37+0100
commit0693e371d66bfe3de2d97ab80e9c9684ec8abc34 (patch)
tree6df4668f712d45dbc32a23a795096bd47a6ee36b /tools/nixery/server/builder/archive.go
parentbf2718cebbd1c7af15c54c6da5685ed6d933cab4 (diff)
feat(server): Apply GZIP compression to all image layers
This fixes #62
Diffstat (limited to 'tools/nixery/server/builder/archive.go')
-rw-r--r--tools/nixery/server/builder/archive.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/tools/nixery/server/builder/archive.go b/tools/nixery/server/builder/archive.go
index 63ea9c73814d..55b3c2a8b79c 100644
--- a/tools/nixery/server/builder/archive.go
+++ b/tools/nixery/server/builder/archive.go
@@ -9,6 +9,7 @@ package builder
 
 import (
 	"archive/tar"
+	"compress/gzip"
 	"io"
 	"os"
 	"path/filepath"
@@ -16,10 +17,11 @@ import (
 	"github.com/google/nixery/server/layers"
 )
 
-// Create a new tarball from each of the paths in the list and write the tarball
-// to the supplied writer.
-func tarStorePaths(l *layers.Layer, w io.Writer) error {
-	t := tar.NewWriter(w)
+// Create a new compressed tarball from each of the paths in the list
+// and write it to the supplied writer.
+func packStorePaths(l *layers.Layer, w io.Writer) error {
+	gz := gzip.NewWriter(w)
+	t := tar.NewWriter(gz)
 
 	for _, path := range l.Contents {
 		err := filepath.Walk(path, tarStorePath(t))
@@ -32,6 +34,10 @@ func tarStorePaths(l *layers.Layer, w io.Writer) error {
 		return err
 	}
 
+	if err := gz.Close(); err != nil {
+		return err
+	}
+
 	return nil
 }