1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/archive/zip/zip.go

40 lines
583 B
Go
Raw Normal View History

2017-01-06 17:23:49 +02:00
package zip
import (
"archive/zip"
"io"
"os"
)
2017-01-15 12:48:27 +02:00
// Archive zip struct
2017-01-06 17:23:49 +02:00
type Archive struct {
z *zip.Writer
}
2017-01-15 12:48:27 +02:00
// Close all closeables
2017-01-06 17:23:49 +02:00
func (a Archive) Close() error {
return a.z.Close()
}
2017-01-15 12:48:27 +02:00
// New zip archive
2017-01-06 17:23:49 +02:00
func New(target *os.File) Archive {
return Archive{
z: zip.NewWriter(target),
}
}
2017-01-15 12:48:27 +02:00
// Add a file to the zip archive
2017-01-06 17:23:49 +02:00
func (a Archive) Add(name, path string) (err error) {
file, err := os.Open(path)
if err != nil {
return
}
defer func() { _ = file.Close() }()
f, err := a.z.Create(name)
if err != nil {
return err
}
_, err = io.Copy(f, file)
return err
}