diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/decompress_bzip2.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/decompress_bzip2.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/decompress_bzip2.go b/vendor/github.com/hashicorp/go-getter/decompress_bzip2.go new file mode 100644 index 0000000..339f4cf --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_bzip2.go | |||
@@ -0,0 +1,45 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "compress/bzip2" | ||
5 | "fmt" | ||
6 | "io" | ||
7 | "os" | ||
8 | "path/filepath" | ||
9 | ) | ||
10 | |||
11 | // Bzip2Decompressor is an implementation of Decompressor that can | ||
12 | // decompress bz2 files. | ||
13 | type Bzip2Decompressor struct{} | ||
14 | |||
15 | func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool) error { | ||
16 | // Directory isn't supported at all | ||
17 | if dir { | ||
18 | return fmt.Errorf("bzip2-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 | // Bzip2 compression is second | ||
34 | bzipR := bzip2.NewReader(f) | ||
35 | |||
36 | // Copy it out | ||
37 | dstF, err := os.Create(dst) | ||
38 | if err != nil { | ||
39 | return err | ||
40 | } | ||
41 | defer dstF.Close() | ||
42 | |||
43 | _, err = io.Copy(dstF, bzipR) | ||
44 | return err | ||
45 | } | ||