代码拉取完成,页面将自动刷新
package main
import (
"compress/gzip"
"io"
"io/ioutil"
"sync"
)
type gzipPool struct {
mutex sync.Mutex
top *gzipPoolEntry
}
type gzipPoolEntry struct {
gz *gzip.Writer
next *gzipPoolEntry
}
func newGzipPool(n int) *gzipPool {
pool := new(gzipPool)
for i := 0; i < n; i++ {
pool.grow()
}
return pool
}
func (p *gzipPool) grow() {
gz, err := gzip.NewWriterLevel(ioutil.Discard, conf.GZipCompression)
if err != nil {
logFatal("Can't init GZip compression: %s", err)
}
p.top = &gzipPoolEntry{
gz: gz,
next: p.top,
}
}
func (p *gzipPool) Get(w io.Writer) *gzip.Writer {
p.mutex.Lock()
defer p.mutex.Unlock()
if p.top == nil {
p.grow()
}
gz := p.top.gz
gz.Reset(w)
p.top = p.top.next
return gz
}
func (p *gzipPool) Put(gz *gzip.Writer) {
p.mutex.Lock()
defer p.mutex.Unlock()
gz.Reset(ioutil.Discard)
p.top = &gzipPoolEntry{gz: gz, next: p.top}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。