mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-11 14:39:28 +02:00
refactor: order methods
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
990fb63aef
commit
c08bb7f24c
@ -16,11 +16,6 @@ type Archive struct {
|
||||
gw *gzip.Writer
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
return a.gw.Close()
|
||||
}
|
||||
|
||||
// New gz archive.
|
||||
func New(target io.Writer) Archive {
|
||||
// the error will be nil since the compression level is valid
|
||||
@ -30,6 +25,11 @@ func New(target io.Writer) Archive {
|
||||
}
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
return a.gw.Close()
|
||||
}
|
||||
|
||||
// Add file to the archive.
|
||||
func (a Archive) Add(f config.File) error {
|
||||
if a.gw.Header.Name != "" {
|
||||
|
@ -9,24 +9,23 @@ import (
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
)
|
||||
|
||||
// Archive as tar.xz.
|
||||
// Archive as tar.
|
||||
type Archive struct {
|
||||
tw *tar.Writer
|
||||
}
|
||||
|
||||
// New tar archive.
|
||||
func New(target io.Writer) Archive {
|
||||
return Archive{
|
||||
tw: tar.NewWriter(target),
|
||||
}
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
return a.tw.Close()
|
||||
}
|
||||
|
||||
// New tar.xz archive.
|
||||
func New(target io.Writer) Archive {
|
||||
tw := tar.NewWriter(target)
|
||||
return Archive{
|
||||
tw: tw,
|
||||
}
|
||||
}
|
||||
|
||||
// Add file to the archive.
|
||||
func (a Archive) Add(f config.File) error {
|
||||
file, err := os.Open(f.Source) // #nosec
|
||||
|
@ -16,14 +16,6 @@ type Archive struct {
|
||||
tw *tar.Archive
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
if err := a.tw.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.gw.Close()
|
||||
}
|
||||
|
||||
// New tar.gz archive.
|
||||
func New(target io.Writer) Archive {
|
||||
// the error will be nil since the compression level is valid
|
||||
@ -35,6 +27,14 @@ func New(target io.Writer) Archive {
|
||||
}
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
if err := a.tw.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.gw.Close()
|
||||
}
|
||||
|
||||
// Add file to the archive.
|
||||
func (a Archive) Add(f config.File) error {
|
||||
return a.tw.Add(f)
|
||||
|
@ -16,14 +16,6 @@ type Archive struct {
|
||||
tw *tar.Archive
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
if err := a.tw.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.xzw.Close()
|
||||
}
|
||||
|
||||
// New tar.xz archive.
|
||||
func New(target io.Writer) Archive {
|
||||
xzw, _ := xz.WriterConfig{DictCap: 16 * 1024 * 1024}.NewWriter(target)
|
||||
@ -34,6 +26,14 @@ func New(target io.Writer) Archive {
|
||||
}
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
if err := a.tw.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.xzw.Close()
|
||||
}
|
||||
|
||||
// Add file to the archive.
|
||||
func (a Archive) Add(f config.File) error {
|
||||
return a.tw.Add(f)
|
||||
|
@ -16,11 +16,6 @@ type Archive struct {
|
||||
z *zip.Writer
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
return a.z.Close()
|
||||
}
|
||||
|
||||
// New zip archive.
|
||||
func New(target io.Writer) Archive {
|
||||
compressor := zip.NewWriter(target)
|
||||
@ -32,6 +27,11 @@ func New(target io.Writer) Archive {
|
||||
}
|
||||
}
|
||||
|
||||
// Close all closeables.
|
||||
func (a Archive) Close() error {
|
||||
return a.z.Close()
|
||||
}
|
||||
|
||||
// Add a file to the zip archive.
|
||||
func (a Archive) Add(f config.File) error {
|
||||
file, err := os.Open(f.Source) // #nosec
|
||||
|
@ -70,7 +70,7 @@ func TestZipFile(t *testing.T) {
|
||||
|
||||
info, err := f.Stat()
|
||||
require.NoError(t, err)
|
||||
require.Truef(t, info.Size() < 900, "archived file should be smaller than %d", info.Size())
|
||||
require.Truef(t, info.Size() < 1000, "archived file should be smaller than %d", info.Size())
|
||||
|
||||
r, err := zip.NewReader(f, info.Size())
|
||||
require.NoError(t, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user