github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/znet/gzip/util.go (about) 1 package gzip 2 3 import ( 4 "compress/gzip" 5 "io/ioutil" 6 ) 7 8 type ( 9 poolCap struct { 10 c chan *gzip.Writer 11 l int 12 } 13 // Config gzip configuration 14 Config struct { 15 // CompressionLevel gzip compression level to use 16 CompressionLevel int 17 // PoolMaxSize maximum number of resource pools 18 PoolMaxSize int 19 // MinContentLength minimum content length to trigger gzip, the unit is in byte. 20 MinContentLength int 21 } 22 ) 23 24 func (bp *poolCap) Get() (g *gzip.Writer, err error) { 25 select { 26 case g = <-bp.c: 27 default: 28 g, err = gzip.NewWriterLevel(ioutil.Discard, bp.l) 29 } 30 31 return 32 } 33 34 func (bp *poolCap) Put(g *gzip.Writer) { 35 select { 36 case bp.c <- g: 37 default: 38 } 39 }