aboutsummaryrefslogtreecommitdiff
path: root/archive
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2017-01-16 11:30:06 -0500
committerMitch Riedstra <mitch@riedstra.us>2017-01-16 11:30:06 -0500
commitd5679be63fe396b5bcd2f01b76799a17a64a83d4 (patch)
treeb32e44dc01738a7bbfd44e50ed8ef7b3d6ca667c /archive
parentab2338daadbb826063c1ff299a9e39bb41e40317 (diff)
downloadsteam-export-d5679be63fe396b5bcd2f01b76799a17a64a83d4.tar.gz
steam-export-d5679be63fe396b5bcd2f01b76799a17a64a83d4.tar.xz
Added ability to extract games. Initial code to delete games. Initial basic progress on a command line application.
Diffstat (limited to 'archive')
-rw-r--r--archive/unarchive.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/archive/unarchive.go b/archive/unarchive.go
new file mode 100644
index 0000000..5089370
--- /dev/null
+++ b/archive/unarchive.go
@@ -0,0 +1,64 @@
+package archive
+
+import (
+ "archive/tar"
+ fp "path/filepath"
+
+ "io"
+ "os"
+)
+
+type Unarchive struct {
+ Input string
+ inputFile *os.File
+ tarReader *tar.Reader
+}
+
+// Extracts a tar arcive to the current working directory
+// This will overwrite everything. So be careful
+func (u *Unarchive) UnTar() error {
+ var err error
+ u.inputFile, err = os.Open(u.Input)
+ if err != nil {
+ return err
+ }
+ defer u.inputFile.Close()
+ u.tarReader = tar.NewReader(u.inputFile)
+
+ for {
+ hdr, err := u.tarReader.Next()
+ if err == io.EOF {
+ // We've reached the end! Whoee
+ break
+ }
+ if err != nil {
+ return err
+ }
+
+ info := hdr.FileInfo()
+ if info.IsDir() {
+ if err = os.MkdirAll(hdr.Name, info.Mode()); err != nil {
+ return err
+ }
+ continue
+ }
+
+ if err = os.MkdirAll(fp.Dir(hdr.Name), info.Mode()); err != nil {
+ return err
+ }
+
+ // Create a file handle to work with
+ // f, err := os.Create(hdr.Name)
+ f, err := os.OpenFile(hdr.Name, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ if _, err := io.Copy(f, u.tarReader); err != nil {
+ return err
+ }
+
+ }
+
+ return nil
+}