-
Notifications
You must be signed in to change notification settings - Fork 1
/
decompress.go
52 lines (47 loc) · 1 KB
/
decompress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package decompress
import (
"io/ioutil"
"strings"
"github.com/kawakatz/unzipR/pkg/unzip"
"github.com/h2non/filetype"
)
// Do decompress the file.
func Do(path string) {
buf, _ := ioutil.ReadFile(path)
kind, _ := filetype.Match(buf)
mime := kind.MIME.Value
switch mime {
case "application/zip":
unzip.Unzip(path)
case "application/x-tar":
unzip.Tar(path)
case "application/x-7z-compressed":
unzip.Sevenzip(path)
case "application/vnd.rar":
unzip.Unrar(path)
case "application/gzip":
if strings.HasSuffix(path, ".tar.gz") || strings.HasSuffix(path, ".tgz") {
unzip.TarGzip(path)
} else {
unzip.Gunzip(path)
}
case "application/x-bzip2":
if strings.HasSuffix(path, ".tar.bz2") {
unzip.TarBz2(path)
} else {
unzip.Bzip2(path)
}
case "application/x-lzip":
if strings.HasSuffix(path, ".tar.lz4") {
unzip.TarLz4(path)
} else {
unzip.Lz4(path)
}
case "application/x-xz":
if strings.HasSuffix(path, ".tar.xz") {
unzip.TarXz(path)
} else {
unzip.Xz(path)
}
}
}