aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/archive/archive.go27
-rw-r--r--lib/archive/unarchive.go19
-rw-r--r--lib/config/config.go4
-rw-r--r--lib/steam/package.go9
4 files changed, 27 insertions, 32 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 {
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 {
diff --git a/lib/config/config.go b/lib/config/config.go
index 839acbf..ab003cb 100644
--- a/lib/config/config.go
+++ b/lib/config/config.go
@@ -9,8 +9,8 @@ import (
)
type Config struct {
- SteamRepositories []string `yaml:"SteamRepositories"`
- DefaultRepository string `yaml:"DefaultRepository"`
+ SteamRepositories []string `yaml:"SteamRepositories" json:"SteamRepositories"`
+ DefaultRepository string `yaml:"DefaultRepository" json:"DefaultRepository"`
Listen string
}
diff --git a/lib/steam/package.go b/lib/steam/package.go
index 2e25994..7a0c6a5 100644
--- a/lib/steam/package.go
+++ b/lib/steam/package.go
@@ -26,8 +26,7 @@ func (l *Library) PackageGameToFile(index int, file, compress string) error {
return err
}
input := []string{"common/" + g, acf}
- a := archive.Archive{Output: output, Input: input}
- err = a.Tar(compress)
+ err = archive.TarToFile(output, input, "gz")
if err != nil {
return err
}
@@ -51,10 +50,8 @@ func (l *Library) ExtractGameFromFile(f, compress string) error {
if err = os.Chdir(l.Folder); err != nil {
return err
}
- u := &archive.Unarchive{
- Input: f,
- }
- if err := u.UnTar(compress); err != nil {
+
+ if err := archive.UnTarFromFile(f, compress); err != nil {
return err
}