diff options
Diffstat (limited to 'lib/archive/archive.go')
| -rw-r--r-- | lib/archive/archive.go | 27 |
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 { |
