diff options
Diffstat (limited to 'steam/archive.go')
| -rw-r--r-- | steam/archive.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/steam/archive.go b/steam/archive.go new file mode 100644 index 0000000..d997051 --- /dev/null +++ b/steam/archive.go @@ -0,0 +1,55 @@ +package steam + +import ( + "archive/tar" + "io" + "os" + "path/filepath" + "strings" +) + +func TarWalkfn(writer *tar.Writer) filepath.WalkFunc { + return func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if info.IsDir() { + return nil + } + + f, err := os.Open(path) + if err != nil { + return err + } + defer f.Close() + + // Convert Windows paths to Unix paths + path = strings.Replace(path, "\\", "/", -1) + + // TODO; See if tar.FileInfoheader() could be used instead + // without the pathing issues I encountered + h := &tar.Header{ + Name: path, + Size: info.Size(), + // I don't like it... but it helps with platform compatibility + Mode: 0664, + ModTime: info.ModTime(), + } + + err = writer.WriteHeader(h) + if err != nil { + return err + } + + _, err = io.Copy(writer, f) + if err != nil { + // TODO: Figure out how to add more useful information to + // These errors + // fmt.Fprintln(os.Stderr, f.Name()) + return err + } + + return nil + } +} |
