aboutsummaryrefslogtreecommitdiff
path: root/lib/archive/archive.go
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2017-02-06 09:06:37 -0500
committerMitch Riedstra <mitch@riedstra.us>2017-02-06 09:06:37 -0500
commit0dc6e92cd018aa0ecea5349a14599279e1a2a574 (patch)
tree81e071239c7a0c5bd9e7d1edbcf25bd9913f656e /lib/archive/archive.go
parentc7ab6d7782486fda6d6327ba8306e474daef677a (diff)
downloadsteam-export-old_dev.tar.gz
steam-export-old_dev.tar.xz
Simplified the Archive library. Added a way to pull the config from the web applicationold_dev
Diffstat (limited to 'lib/archive/archive.go')
-rw-r--r--lib/archive/archive.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/archive/archive.go b/lib/archive/archive.go
index 639a864..2d0f4fd 100644
--- a/lib/archive/archive.go
+++ b/lib/archive/archive.go
@@ -12,26 +12,26 @@ import (
"strings"
)
-type Archive struct {
- Output string
- Input []string
- file *os.File
-}
-
-func (a *Archive) Tar(compressionType string) error {
+func TarToFile(Output string, Input []string, compressionType string) error {
var err error
- if a.file, err = os.Create(a.Output); err != nil {
+ file, err := os.Create(Output)
+ if err != nil {
return err
}
- defer a.file.Close()
+ defer file.Close()
+
+ return Tar(file, Input, compressionType)
+}
+
+func Tar(writer io.Writer, Input []string, compressionType string) error {
var twriter *tar.Writer
// Set the compression type... if any
switch compressionType {
case "gz":
- gzwriter, err := gzip.NewWriterLevel(a.file, gzip.BestSpeed)
+ gzwriter, err := gzip.NewWriterLevel(writer, gzip.BestSpeed)
if err != nil {
return err
}
@@ -39,21 +39,20 @@ func (a *Archive) Tar(compressionType string) error {
// Write to the gzip writer
twriter = tar.NewWriter(gzwriter)
default:
- // Write directly to the file
- twriter = tar.NewWriter(a.file)
+ // Write directly to the io.Writer
+ twriter = tar.NewWriter(writer)
}
// Close off the tar writer when we're done
defer twriter.Close()
- for _, v := range a.Input {
+ for _, v := range Input {
if err := filepath.Walk(v, tarWalkfn(twriter)); err != nil {
return err
}
}
return nil
-
}
func tarWalkfn(writer *tar.Writer) filepath.WalkFunc {