2018-08-05 10:23:39 -03:00
|
|
|
// Package archive provides tar.gz and zip archiving
|
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
2022-05-11 21:54:28 -03:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2018-08-05 10:23:39 -03:00
|
|
|
|
2019-02-07 12:12:20 -02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/gzip"
|
2021-08-31 23:09:18 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/tar"
|
2019-02-07 12:12:20 -02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/targz"
|
2020-04-13 08:53:03 -04:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/tarxz"
|
2018-08-05 10:23:39 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/zip"
|
2021-07-21 22:09:02 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2018-08-05 10:23:39 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Archive represents a compression archive files from disk can be written to.
|
|
|
|
type Archive interface {
|
|
|
|
Close() error
|
2021-07-21 22:09:02 -03:00
|
|
|
Add(f config.File) error
|
2018-08-05 10:23:39 -03:00
|
|
|
}
|
|
|
|
|
2019-02-07 12:12:20 -02:00
|
|
|
// New archive.
|
2022-05-11 21:54:28 -03:00
|
|
|
func New(w io.Writer, format string) (Archive, error) {
|
|
|
|
switch format {
|
|
|
|
case "tar.gz":
|
|
|
|
return targz.New(w), nil
|
|
|
|
case "tar":
|
|
|
|
return tar.New(w), nil
|
|
|
|
case "gz":
|
|
|
|
return gzip.New(w), nil
|
|
|
|
case "tar.xz":
|
|
|
|
return tarxz.New(w), nil
|
|
|
|
case "zip":
|
|
|
|
return zip.New(w), nil
|
2019-02-07 12:12:20 -02:00
|
|
|
}
|
2022-05-11 21:54:28 -03:00
|
|
|
return nil, fmt.Errorf("invalid archive format: %s", format)
|
2018-08-05 10:23:39 -03:00
|
|
|
}
|