mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-08 01:36:13 +00:00

- 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
39 lines
719 B
Go
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
|
|
}
|