From dbab9ab4fb86309ae812ea65c59bfb81ff08e02a Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Thu, 18 Oct 2018 12:57:54 +1300 Subject: [PATCH] Add --compress flag to tar-split asm The Go implementation of gzip is the only known to produce compressed layers with the expected digest hashes. This change allows compressed tar layer files to be produced, which is useful for exporting layers from non-Go tools. --- cmd/tar-split/asm.go | 6 ++++++ cmd/tar-split/main.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/cmd/tar-split/asm.go b/cmd/tar-split/asm.go index 7665f95..fb77df4 100644 --- a/cmd/tar-split/asm.go +++ b/cmd/tar-split/asm.go @@ -37,6 +37,12 @@ func CommandAsm(c *cli.Context) { outputStream = fh } + if c.Bool("compress") { + zipper := gzip.NewWriter(outputStream) + defer zipper.Close() + outputStream = zipper + } + // Get the tar metadata reader mf, err := os.Open(c.String("input")) if err != nil { diff --git a/cmd/tar-split/main.go b/cmd/tar-split/main.go index 5f039ab..37e0f64 100644 --- a/cmd/tar-split/main.go +++ b/cmd/tar-split/main.go @@ -69,6 +69,11 @@ func main() { Value: "", Usage: "relative path of extracted tar", }, + cli.BoolFlag{ + Name: "compress", + Usage: "gzip compress the output", + // defaults to false + }, }, }, {