github.com/joselitofilho/goreleaser@v0.155.1-0.20210123221854-e4891856c593/pkg/archive/archive.go (about) 1 // Package archive provides tar.gz and zip archiving 2 package archive 3 4 import ( 5 "os" 6 "strings" 7 8 "github.com/goreleaser/goreleaser/pkg/archive/gzip" 9 "github.com/goreleaser/goreleaser/pkg/archive/targz" 10 "github.com/goreleaser/goreleaser/pkg/archive/tarxz" 11 "github.com/goreleaser/goreleaser/pkg/archive/zip" 12 ) 13 14 // Archive represents a compression archive files from disk can be written to. 15 type Archive interface { 16 Close() error 17 Add(name, path string) error 18 } 19 20 // New archive. 21 func New(file *os.File) Archive { 22 if strings.HasSuffix(file.Name(), ".tar.gz") { 23 return targz.New(file) 24 } 25 if strings.HasSuffix(file.Name(), ".gz") { 26 return gzip.New(file) 27 } 28 if strings.HasSuffix(file.Name(), ".tar.xz") { 29 return tarxz.New(file) 30 } 31 if strings.HasSuffix(file.Name(), ".zip") { 32 return zip.New(file) 33 } 34 return targz.New(file) 35 }