diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/decompress_gzip.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/decompress_gzip.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/decompress_gzip.go b/vendor/github.com/hashicorp/go-getter/decompress_gzip.go new file mode 100644 index 0000000..2001054 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_gzip.go | |||
@@ -0,0 +1,49 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "compress/gzip" | ||
5 | "fmt" | ||
6 | "io" | ||
7 | "os" | ||
8 | "path/filepath" | ||
9 | ) | ||
10 | |||
11 | // GzipDecompressor is an implementation of Decompressor that can | ||
12 | // decompress bz2 files. | ||
13 | type GzipDecompressor struct{} | ||
14 | |||
15 | func (d *GzipDecompressor) Decompress(dst, src string, dir bool) error { | ||
16 | // Directory isn't supported at all | ||
17 | if dir { | ||
18 | return fmt.Errorf("gzip-compressed files can only unarchive to a single file") | ||
19 | } | ||
20 | |||
21 | // If we're going into a directory we should make that first | ||
22 | if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil { | ||
23 | return err | ||
24 | } | ||
25 | |||
26 | // File first | ||
27 | f, err := os.Open(src) | ||
28 | if err != nil { | ||
29 | return err | ||
30 | } | ||
31 | defer f.Close() | ||
32 | |||
33 | // gzip compression is second | ||
34 | gzipR, err := gzip.NewReader(f) | ||
35 | if err != nil { | ||
36 | return err | ||
37 | } | ||
38 | defer gzipR.Close() | ||
39 | |||
40 | // Copy it out | ||
41 | dstF, err := os.Create(dst) | ||
42 | if err != nil { | ||
43 | return err | ||
44 | } | ||
45 | defer dstF.Close() | ||
46 | |||
47 | _, err = io.Copy(dstF, gzipR) | ||
48 | return err | ||
49 | } | ||