Commit 751b9153 authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

Move `gzip` to `archives.CreateGzipArchive`

parent be367359
......@@ -55,14 +55,7 @@ func (c *ArtifactsUploaderCommand) writeGzipFile(w *io.PipeWriter, fileName stri
}
func (c *ArtifactsUploaderCommand) generateGzipStream(w *io.PipeWriter) {
var err error
for fileName, fileInfo := range c.files {
err = c.writeGzipFile(w, fileName, fileInfo)
if err != nil {
break
}
}
err := archives.CreateGzipArchive(w, c.sortedFiles())
w.CloseWithError(err)
}
......
package archives
import (
"compress/gzip"
"io"
"os"
)
func writeGzipFile(w io.Writer, fileName string, fileInfo os.FileInfo) error {
gz := gzip.NewWriter(w)
gz.Header.Name = fileInfo.Name()
gz.Header.Comment = fileName
gz.Header.ModTime = fileInfo.ModTime()
defer gz.Close()
file, err := os.Open(fileName)
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(gz, file)
return err
}
func CreateGzipArchive(w io.Writer, fileNames []string) error {
for _, fileName := range fileNames {
fi, err := os.Stat(fileName)
if err != nil {
return err
}
err = writeGzipFile(w, fileName, fi)
if err != nil {
return err
}
}
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment