1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-10-30 23:58:09 +02:00
Files
goreleaser/pipeline/archive/zip/zip.go
Carlos Alexandro Becker 3bc428120d adding more tests and godocs
2017-04-14 15:39:32 -03:00

42 lines
675 B
Go

// Package zip implements the Archive interface providing zip archiving
// and compression.
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
}