2018-08-05 15:23:39 +02:00
|
|
|
// Package archive provides tar.gz and zip archiving
|
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
2022-05-12 02:54:28 +02:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2023-04-08 03:53:15 +02:00
|
|
|
"os"
|
2018-08-05 15:23:39 +02:00
|
|
|
|
2019-02-07 16:12:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/gzip"
|
2021-09-01 04:09:18 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/tar"
|
2019-02-07 16:12:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/targz"
|
2020-04-13 14:53:03 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/tarxz"
|
2018-08-05 15:23:39 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/zip"
|
2021-07-22 03:09:02 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2018-08-05 15:23:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Archive represents a compression archive files from disk can be written to.
|
|
|
|
type Archive interface {
|
|
|
|
Close() error
|
2021-07-22 03:09:02 +02:00
|
|
|
Add(f config.File) error
|
2018-08-05 15:23:39 +02:00
|
|
|
}
|
|
|
|
|
2019-02-07 16:12:20 +02:00
|
|
|
// New archive.
|
2022-05-12 02:54:28 +02:00
|
|
|
func New(w io.Writer, format string) (Archive, error) {
|
|
|
|
switch format {
|
2023-04-08 04:40:49 +02:00
|
|
|
case "tar.gz", "tgz":
|
2022-05-12 02:54:28 +02:00
|
|
|
return targz.New(w), nil
|
|
|
|
case "tar":
|
|
|
|
return tar.New(w), nil
|
|
|
|
case "gz":
|
|
|
|
return gzip.New(w), nil
|
2023-04-08 04:40:49 +02:00
|
|
|
case "tar.xz", "txz":
|
2022-05-12 02:54:28 +02:00
|
|
|
return tarxz.New(w), nil
|
|
|
|
case "zip":
|
|
|
|
return zip.New(w), nil
|
2019-02-07 16:12:20 +02:00
|
|
|
}
|
2022-05-12 02:54:28 +02:00
|
|
|
return nil, fmt.Errorf("invalid archive format: %s", format)
|
2018-08-05 15:23:39 +02:00
|
|
|
}
|
2023-04-08 03:53:15 +02:00
|
|
|
|
|
|
|
// Copying copies the source archive into a new one, which can be appended at.
|
|
|
|
// Source needs to be in the specified format.
|
|
|
|
func Copying(r *os.File, w io.Writer, format string) (Archive, error) {
|
|
|
|
switch format {
|
|
|
|
case "tar.gz", "tgz":
|
|
|
|
return targz.Copying(r, w)
|
|
|
|
case "tar":
|
|
|
|
return tar.Copying(r, w)
|
|
|
|
case "zip":
|
|
|
|
return zip.Copying(r, w)
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("invalid archive format: %s", format)
|
|
|
|
}
|