]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/go-getter/decompress_tbz2.go
Merge branch 'fix_read_test' of github.com:alexandreFre/terraform-provider-statuscake
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / decompress_tbz2.go
CommitLineData
bae9f6d2
JC
1package getter
2
3import (
bae9f6d2 4 "compress/bzip2"
bae9f6d2
JC
5 "os"
6 "path/filepath"
7)
8
9// TarBzip2Decompressor is an implementation of Decompressor that can
10// decompress tar.bz2 files.
11type TarBzip2Decompressor struct{}
12
13func (d *TarBzip2Decompressor) Decompress(dst, src string, dir bool) error {
14 // If we're going into a directory we should make that first
15 mkdir := dst
16 if !dir {
17 mkdir = filepath.Dir(dst)
18 }
19 if err := os.MkdirAll(mkdir, 0755); err != nil {
20 return err
21 }
22
23 // File first
24 f, err := os.Open(src)
25 if err != nil {
26 return err
27 }
28 defer f.Close()
29
30 // Bzip2 compression is second
31 bzipR := bzip2.NewReader(f)
15c0b25d 32 return untar(bzipR, dst, src, dir)
bae9f6d2 33}