1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-08 10:45:04 +02:00
imgproxy/gzip.go

27 lines
389 B
Go
Raw Normal View History

2018-10-05 17:17:36 +02:00
package main
import (
"compress/gzip"
"io"
"os"
"sync"
)
var nullwriter, _ = os.Open("/dev/null")
var gzipPool = sync.Pool{
New: func() interface{} {
gz, _ := gzip.NewWriterLevel(nullwriter, conf.GZipCompression)
return gz
},
}
func gzipData(data []byte, w io.Writer) {
gz := gzipPool.Get().(*gzip.Writer)
2019-01-09 14:41:00 +02:00
defer gzipPool.Put(gz)
2018-10-05 17:17:36 +02:00
gz.Reset(w)
gz.Write(data)
gz.Close()
}