getEncoder returns a writer that encodes and writes to the provided writer, and a cleanup func.
(name string, w io.Writer)
| 362 | |
| 363 | // getEncoder returns a writer that encodes and writes to the provided writer, and a cleanup func. |
| 364 | func (c *Compressor) getEncoder(name string, w io.Writer) (io.WriteCloser, func()) { |
| 365 | if pool, ok := c.pooledEncoders[name]; ok { |
| 366 | encoder, typeOK := pool.Get().(ioResetterWriter) |
| 367 | if !typeOK { |
| 368 | return nil, nil |
| 369 | } |
| 370 | cleanup := func() { |
| 371 | pool.Put(encoder) |
| 372 | } |
| 373 | encoder.Reset(w) |
| 374 | return encoder, cleanup |
| 375 | } |
| 376 | if fn, ok := c.encoders[name]; ok { |
| 377 | return fn(w, c.level), func() {} |
| 378 | } |
| 379 | return nil, nil |
| 380 | } |
| 381 | |
| 382 | func matchAcceptEncoding(accepted []string, encoding string) bool { |
| 383 | for _, v := range accepted { |