]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package getter |
2 | ||
3 | import ( | |
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. | |
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) | |
15c0b25d | 32 | return untar(bzipR, dst, src, dir) |
bae9f6d2 | 33 | } |