github.com/apcera/util@v0.0.0-20180322191801-7a50bc84ee48/tarhelper/xz/xz.go (about) 1 // Copyright 2014 Apcera Inc. All rights reserved. 2 3 package xz 4 5 import ( 6 "bufio" 7 "bytes" 8 "io" 9 10 "github.com/apcera/util/tarhelper" 11 xz "github.com/remyoudompheng/go-liblzma" 12 ) 13 14 func init() { 15 tarhelper.AddDecompressor("xz", &XZDecompressor{}) 16 } 17 18 type XZDecompressor struct{} 19 20 func (c *XZDecompressor) Detect(br *bufio.Reader) bool { 21 data, err := br.Peek(6) 22 if err != nil { 23 return false 24 } 25 return bytes.Equal(data, []byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}) 26 } 27 28 func (c *XZDecompressor) NewReader(src io.Reader) (io.Reader, error) { 29 return xz.NewReader(src) 30 }