1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00
goreleaser/pkg/archive/archive.go
Carlos A Becker c41d6de833
feat: support tgz and txz as archive formats
We support `.tar.gz` since the beginning, and `.tar.xz` for a long time.

`.tgz` and `.txz` are just commonly used shorthands for the same
formats.

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-04-08 02:40:54 +00:00

53 lines
1.3 KiB
Go

// Package archive provides tar.gz and zip archiving
package archive
import (
"fmt"
"io"
"os"
"github.com/goreleaser/goreleaser/pkg/archive/gzip"
"github.com/goreleaser/goreleaser/pkg/archive/tar"
"github.com/goreleaser/goreleaser/pkg/archive/targz"
"github.com/goreleaser/goreleaser/pkg/archive/tarxz"
"github.com/goreleaser/goreleaser/pkg/archive/zip"
"github.com/goreleaser/goreleaser/pkg/config"
)
// Archive represents a compression archive files from disk can be written to.
type Archive interface {
Close() error
Add(f config.File) error
}
// New archive.
func New(w io.Writer, format string) (Archive, error) {
switch format {
case "tar.gz", "tgz":
return targz.New(w), nil
case "tar":
return tar.New(w), nil
case "gz":
return gzip.New(w), nil
case "tar.xz", "txz":
return tarxz.New(w), nil
case "zip":
return zip.New(w), nil
}
return nil, fmt.Errorf("invalid archive format: %s", format)
}
// 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)
}