2018-08-05 15:23:39 +02:00
|
|
|
// Package archive provides tar.gz and zip archiving
|
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2019-02-07 16:12:20 +02:00
|
|
|
"strings"
|
2018-08-05 15:23:39 +02:00
|
|
|
|
2019-02-07 16:12:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/gzip"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/targz"
|
2018-08-05 15:23:39 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/zip"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Archive represents a compression archive files from disk can be written to.
|
|
|
|
type Archive interface {
|
|
|
|
Close() error
|
|
|
|
Add(name, path string) error
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:12:20 +02:00
|
|
|
// New archive.
|
2018-08-05 15:23:39 +02:00
|
|
|
func New(file *os.File) Archive {
|
2019-02-07 16:12:20 +02:00
|
|
|
if strings.HasSuffix(file.Name(), ".tar.gz") {
|
|
|
|
return targz.New(file)
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(file.Name(), ".gz") {
|
|
|
|
return gzip.New(file)
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(file.Name(), ".zip") {
|
2018-08-05 15:23:39 +02:00
|
|
|
return zip.New(file)
|
|
|
|
}
|
2019-02-07 16:12:20 +02:00
|
|
|
return targz.New(file)
|
2018-08-05 15:23:39 +02:00
|
|
|
}
|