1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00
Carlos Alexandro Becker 431c28b2bd
fix: gosec lint issues
2018-09-04 09:26:45 -03:00

55 lines
906 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 io.Writer) 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) // #nosec
if err != nil {
return
}
defer file.Close() // nolint: errcheck
info, err := file.Stat()
if err != nil {
return
}
if info.IsDir() {
return
}
header, err := zip.FileInfoHeader(info)
if err != nil {
return err
}
header.Name = name
header.Method = zip.Deflate
w, err := a.z.CreateHeader(header)
if err != nil {
return err
}
_, err = io.Copy(w, file)
return err
}