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
2017-01-15 08:49:49 -02:00

40 lines
583 B
Go

package zip
import (
"archive/zip"
"io"
"os"
)
// Archive zip struct
type Archive struct {
z *zip.Writer
}
// Close all closeables
func (a Archive) Close() error {
return a.z.Close()
}
// New zip archive
func New(target *os.File) Archive {
return Archive{
z: zip.NewWriter(target),
}
}
// Add a file to the zip archive
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
}