]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - 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
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
13 func (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)
32 return untar(bzipR, dst, src, dir)
33 }