github.com/hashicorp/go-getter/v2@v2.2.2/decompress_tbz2.go (about) 1 package getter 2 3 import ( 4 "compress/bzip2" 5 "os" 6 "path/filepath" 7 ) 8 9 // TarBzip2Decompressor is an implementation of Decompressor that can 10 // decompress tar.bz2 files. 11 type TarBzip2Decompressor struct { 12 // FileSizeLimit limits the total size of all 13 // decompressed files. 14 // 15 // The zero value means no limit. 16 FileSizeLimit int64 17 18 // FilesLimit limits the number of files that are 19 // allowed to be decompressed. 20 // 21 // The zero value means no limit. 22 FilesLimit int 23 } 24 25 func (d *TarBzip2Decompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error { 26 // If we're going into a directory we should make that first 27 mkdir := dst 28 if !dir { 29 mkdir = filepath.Dir(dst) 30 } 31 if err := os.MkdirAll(mkdir, mode(0755, umask)); err != nil { 32 return err 33 } 34 35 // File first 36 f, err := os.Open(src) 37 if err != nil { 38 return err 39 } 40 defer f.Close() 41 42 // Bzip2 compression is second 43 bzipR := bzip2.NewReader(f) 44 return untar(bzipR, dst, src, dir, umask, d.FileSizeLimit, d.FilesLimit) 45 }