aboutsummaryrefslogtreecommitdiff
path: root/archive
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2017-01-06 18:06:34 -0500
committerMitch Riedstra <mitch@riedstra.us>2017-01-06 18:06:34 -0500
commitdaa78703abcd467936fb498a1ca4deb85a2fe419 (patch)
tree3105a06622c45413d93b92cf3ff83fd02f204b09 /archive
parentc5d68db9fb5f831106ce3eb12048e8f9005e531b (diff)
downloadsteam-export-daa78703abcd467936fb498a1ca4deb85a2fe419.tar.gz
steam-export-daa78703abcd467936fb498a1ca4deb85a2fe419.tar.xz
Added an archive library and ability to package steam games
Diffstat (limited to 'archive')
-rw-r--r--archive/archive.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/archive/archive.go b/archive/archive.go
new file mode 100644
index 0000000..2fe039d
--- /dev/null
+++ b/archive/archive.go
@@ -0,0 +1,88 @@
+package archive
+
+import (
+ "archive/tar"
+ "path/filepath"
+
+ "fmt"
+ "io"
+ "os"
+)
+
+type Archive struct {
+ Output, Input string
+ file *os.File
+ writer *tar.Writer
+}
+
+func (a *Archive) Tar() error {
+ var err error
+ if a.file, err = os.Create(a.Output); err != nil {
+ return err
+ }
+
+ defer a.file.Close()
+
+ a.writer = tar.NewWriter(a.file)
+ defer a.writer.Close()
+
+ if err := filepath.Walk(a.Input, a.tarWalkfn()); err != nil {
+ return err
+ }
+
+ fmt.Fprintln(os.Stderr, "done, remove me later")
+ return nil
+
+}
+
+func (a *Archive) tarWalkfn() filepath.WalkFunc {
+ // This is an interesting trick to get around scoping issues
+ return func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if info.IsDir() {
+ return nil
+ }
+ // fmt.Fprintf(os.Stderr, "%s: Fileinfo: %s", path, info.IsDir())
+
+ f, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+ // defer f.Close()
+
+ h := &tar.Header{
+ Name: path,
+ Size: info.Size(),
+ Mode: int64(info.Mode()),
+ ModTime: info.ModTime(),
+ }
+
+ // h, err := tar.FileInfoHeader(info, "")
+ if err != nil {
+ return err
+ }
+
+ err = a.writer.WriteHeader(h)
+ if err != nil {
+ /*
+ fmt.Fprintf(os.Stderr, "This header has a problem: %s\n", h)
+ fmt.Fprintln(os.Stderr, "FUCK this error")
+ fmt.Fprintln(os.Stderr, err)
+ */
+ // fmt.Fprintln(os.Stderr, "Here!")
+ return err
+ }
+
+ _, err = io.Copy(a.writer, f)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "here")
+ fmt.Fprintln(os.Stderr, f.Name())
+ return err
+ }
+
+ return nil
+ }
+}