12 // TarBzip2Decompressor is an implementation of Decompressor that can
13 // decompress tar.bz2 files.
14 type TarBzip2Decompressor struct{}
16 func (d *TarBzip2Decompressor) Decompress(dst, src string, dir bool) error {
17 // If we're going into a directory we should make that first
20 mkdir = filepath.Dir(dst)
22 if err := os.MkdirAll(mkdir, 0755); err != nil {
27 f, err := os.Open(src)
33 // Bzip2 compression is second
34 bzipR := bzip2.NewReader(f)
36 // Once bzip decompressed we have a tar format
37 tarR := tar.NewReader(bzipR)
40 hdr, err := tarR.Next()
44 return fmt.Errorf("empty archive: %s", src)
55 path = filepath.Join(path, hdr.Name)
58 if hdr.FileInfo().IsDir() {
60 return fmt.Errorf("expected a single file: %s", src)
63 // A directory, just make the directory and continue unarchiving...
64 if err := os.MkdirAll(path, 0755); err != nil {
71 // We have a file. If we already decoded, then it is an error
73 return fmt.Errorf("expected a single file, got multiple: %s", src)
76 // Mark that we're done so future in single file mode errors
79 // Open the file for writing
80 dstF, err := os.Create(path)
84 _, err = io.Copy(dstF, tarR)
91 if err := os.Chmod(path, hdr.FileInfo().Mode()); err != nil {