Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions internal/cli/build-cpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
package cli

import (
"compress/gzip"
"context"
"fmt"
"io"
"os"
"runtime"
"strings"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -109,8 +112,15 @@ func BuildCPIOCmd(ctx context.Context, dest string, opts ...build.Option) error
}
defer f.Close()

// TODO(mattmoor): Consider wrapping in a gzip writer if the filename
// ends in .gz
// Use a gzip-compressed writer when the output filename ends with .gz.
var w io.Writer = f

return cpio.FromLayer(layer, f)
if strings.HasSuffix(dest, ".gz") {
gzw := gzip.NewWriter(f)
defer gzw.Close()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should probably check the error returned by the gzip writer (gzq.Close() writes a footer)


w = gzw
}

return cpio.FromLayer(layer, w)
}