webhookd/pkg/tools/compress.go
Nicolas Carlier 14c214efdf refactor(): Complete refactoring.
- No external dependencies
- No predefined directory structure
- Able to launch any kind of shell script with custom parameters
- Get script output as text event stream (SSE)
- Using common Makefiles
- Extends docker/dind Docker image
2018-01-02 16:11:59 +00:00

39 lines
719 B
Go

package tools
import (
"bufio"
"compress/gzip"
"fmt"
"log"
"os"
)
// CompressFile is a simple file gzipper.
func CompressFile(filename string) (zipfile string, err error) {
zipfile = fmt.Sprintf("%s.gz", filename)
in, err := os.Open(filename)
if err != nil {
return
}
out, err := os.Create(zipfile)
if err != nil {
log.Println("Unable to create gzip file", err)
return
}
// buffer readers from file, writes to pipe
bufin := bufio.NewReader(in)
// gzip wraps buffer writer and wr
gw := gzip.NewWriter(out)
defer gw.Close()
_, err = bufin.WriteTo(gw)
if err != nil {
log.Println("Unable to write into the gzip file", err)
return
}
log.Println("Gzip file created: ", zipfile)
return
}