mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-09 19:52:30 +02:00
fasthttp; Optimized memory allocation
This commit is contained in:
24
gzip.go
Normal file
24
gzip.go
Normal file
@@ -0,0 +1,24 @@
|
||||
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)
|
||||
gz.Reset(w)
|
||||
gz.Write(data)
|
||||
gz.Close()
|
||||
}
|
Reference in New Issue
Block a user