add support for xz compression #6523
This commit is contained in:
parent
9c6b4287e5
commit
999a53ca76
|
@ -105,6 +105,16 @@ func main() {
|
|||
c.Close()
|
||||
fmt.Printf("lz4:\twriter %s\treader %s\tsize %d\n", resw.T.String(), resr.T.String(), c.sw)
|
||||
|
||||
c, err = NewCompressor("/tmp/image.r", "/tmp/image.w")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resw = testing.Benchmark(c.BenchmarkXZWriter)
|
||||
c.w.Seek(0, 0)
|
||||
resr = testing.Benchmark(c.BenchmarkXZReader)
|
||||
c.Close()
|
||||
fmt.Printf("xz:\twriter %s\treader %s\tsize %d\n", resw.T.String(), resr.T.String(), c.sw)
|
||||
|
||||
}
|
||||
|
||||
func (c *Compressor) BenchmarkGZIPWriter(b *testing.B) {
|
||||
|
@ -195,3 +205,25 @@ func (c *Compressor) BenchmarkLZ4Reader(b *testing.B) {
|
|||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Compressor) BenchmarkXZWriter(b *testing.B) {
|
||||
cw := xz.NewWriter(c.w)
|
||||
b.ResetTimer()
|
||||
|
||||
_, err := io.Copy(cw, c.r)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
cw.Close()
|
||||
c.w.Sync()
|
||||
}
|
||||
|
||||
func (c *Compressor) BenchmarkXZReader(b *testing.B) {
|
||||
cr := xz.NewReader(c.w)
|
||||
b.ResetTimer()
|
||||
|
||||
_, err := io.Copy(ioutil.Discard, cr)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/hashicorp/packer/template/interpolate"
|
||||
"github.com/klauspost/pgzip"
|
||||
"github.com/pierrec/lz4"
|
||||
"github.com/ulikunitz/xz"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -142,6 +143,11 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||
runtime.GOMAXPROCS(-1), target))
|
||||
output, err = makeLZ4Writer(outputFile, p.config.CompressionLevel)
|
||||
defer output.Close()
|
||||
case "xz":
|
||||
ui.Say(fmt.Sprintf("Using xz compression with %d cores for %s",
|
||||
runtime.GOMAXPROCS(-1), target))
|
||||
output, err = makeXZWriter(outputFile, p.config.CompressionLevel)
|
||||
defer output.Close()
|
||||
case "pgzip":
|
||||
ui.Say(fmt.Sprintf("Using pgzip compression with %d cores for %s",
|
||||
runtime.GOMAXPROCS(-1), target))
|
||||
|
@ -209,6 +215,7 @@ func (config *Config) detectFromFilename() {
|
|||
"gz": "pgzip",
|
||||
"lz4": "lz4",
|
||||
"bgzf": "bgzf",
|
||||
"xz": "xz",
|
||||
}
|
||||
|
||||
if config.Format == "" {
|
||||
|
@ -273,6 +280,14 @@ func makeLZ4Writer(output io.WriteCloser, compressionLevel int) (io.WriteCloser,
|
|||
return lzwriter, nil
|
||||
}
|
||||
|
||||
func makeXZWriter(output io.WriteCloser, compressionLevel int) (io.WriteCloser, error) {
|
||||
xzwriter, err := xz.NewWriter(output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return xzwriter, nil
|
||||
}
|
||||
|
||||
func makePgzipWriter(output io.WriteCloser, compressionLevel int) (io.WriteCloser, error) {
|
||||
gzipWriter, err := pgzip.NewWriterLevel(output, compressionLevel)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue