aboutsummaryrefslogtreecommitdiff
path: root/lib/archive/unarchive.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/archive/unarchive.go')
-rw-r--r--lib/archive/unarchive.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/archive/unarchive.go b/lib/archive/unarchive.go
index 8a5617e..463216f 100644
--- a/lib/archive/unarchive.go
+++ b/lib/archive/unarchive.go
@@ -12,25 +12,24 @@ import (
"strings"
)
-type Unarchive struct {
- Input string
- tarReader *tar.Reader
-}
-
// Extracts a tar arcive to the current working directory
// This will overwrite everything. So be careful
-func (u *Unarchive) UnTar(compressionType string) error {
- f, err := os.Open(u.Input)
+func UnTarFromFile(InputFile, compressionType string) error {
+ r, err := os.Open(InputFile)
if err != nil {
return err
}
- defer f.Close()
+ defer r.Close()
+
+ return UnTar(r, compressionType)
+}
+func UnTar(r io.Reader, compressionType string) error {
var treader *tar.Reader
switch compressionType {
case "gz":
- gzreader, err := gzip.NewReader(f)
+ gzreader, err := gzip.NewReader(r)
if err != nil {
return err
}
@@ -38,7 +37,7 @@ func (u *Unarchive) UnTar(compressionType string) error {
treader = tar.NewReader(gzreader)
default:
// Read from the file directly
- treader = tar.NewReader(f)
+ treader = tar.NewReader(r)
}
for {