66 "encoding/json"
77 "fmt"
88 "io"
9- "os/exec"
109
1110 "github.com/andybalholm/brotli"
1211 "github.com/klauspost/compress/zstd"
@@ -116,45 +115,11 @@ func brotliCodec(quality int) codec {
116115 }
117116}
118117
119- func runPipe (input []byte , name string , args ... string ) ([]byte , error ) {
120- cmd := exec .Command (name , args ... )
121- cmd .Stdin = bytes .NewReader (input )
122- var out , errBuf bytes.Buffer
123- cmd .Stdout = & out
124- cmd .Stderr = & errBuf
125- if err := cmd .Run (); err != nil {
126- return nil , fmt .Errorf ("%s: %w: %s" , name , err , errBuf .String ())
127- }
128- return out .Bytes (), nil
129- }
130-
131- // xzCodec shells out to the system xz binary (real liblzma) so the LZMA
132- // numbers reflect `xz -9`, not a weaker pure-Go reimplementation.
133- func xzCodec () codec {
134- return codec {
135- name : "json+xz9" ,
136- encode : func (nodes wfv1.Nodes ) ([]byte , error ) {
137- b , err := marshalJSON (nodes )
138- if err != nil {
139- return nil , err
140- }
141- return runPipe (b , "xz" , "-9" , "-T1" , "-c" )
142- },
143- decode : func (b []byte ) (wfv1.Nodes , error ) {
144- raw , err := runPipe (b , "xz" , "-d" , "-c" )
145- if err != nil {
146- return nil , err
147- }
148- return unmarshalJSON (raw )
149- },
150- }
151- }
152-
153118// buildCodecs returns the codec matrix from the spec, in display order. The
154119// first codec (json+gzip via util/file, i.e. the current packer path) is the
155120// baseline that ratios are computed against. brotliLevels adds one codec per
156- // quality (0-11); withXz adds the xz -9 reference codec .
157- func buildCodecs (ctx context.Context , level zstd.EncoderLevel , jsonDict , protoDict []byte , brotliLevels []int , withXz bool ) ([]codec , error ) {
121+ // quality (0-11).
122+ func buildCodecs (ctx context.Context , level zstd.EncoderLevel , jsonDict , protoDict []byte , brotliLevels []int ) ([]codec , error ) {
158123 gzipCodec := codec {
159124 name : "json+gzip" ,
160125 encode : func (nodes wfv1.Nodes ) ([]byte , error ) {
@@ -177,12 +142,6 @@ func buildCodecs(ctx context.Context, level zstd.EncoderLevel, jsonDict, protoDi
177142 for _ , q := range brotliLevels {
178143 codecs = append (codecs , brotliCodec (q ))
179144 }
180- if withXz {
181- if _ , err := exec .LookPath ("xz" ); err != nil {
182- return nil , fmt .Errorf ("-xz requested but no xz binary in PATH: %w" , err )
183- }
184- codecs = append (codecs , xzCodec ())
185- }
186145 for _ , c := range []struct {
187146 name string
188147 dict []byte
0 commit comments