]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/go-getter/decompress_tgz.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / decompress_tgz.go
CommitLineData
bae9f6d2
JC
1package getter
2
3import (
bae9f6d2
JC
4 "compress/gzip"
5 "fmt"
bae9f6d2
JC
6 "os"
7 "path/filepath"
8)
9
10// TarGzipDecompressor is an implementation of Decompressor that can
11// decompress tar.gzip files.
12type TarGzipDecompressor struct{}
13
14func (d *TarGzipDecompressor) Decompress(dst, src string, dir bool) error {
15 // If we're going into a directory we should make that first
16 mkdir := dst
17 if !dir {
18 mkdir = filepath.Dir(dst)
19 }
20 if err := os.MkdirAll(mkdir, 0755); err != nil {
21 return err
22 }
23
24 // File first
25 f, err := os.Open(src)
26 if err != nil {
27 return err
28 }
29 defer f.Close()
30
31 // Gzip compression is second
32 gzipR, err := gzip.NewReader(f)
33 if err != nil {
34 return fmt.Errorf("Error opening a gzip reader for %s: %s", src, err)
35 }
36 defer gzipR.Close()
37
15c0b25d 38 return untar(gzipR, dst, src, dir)
bae9f6d2 39}