SetLevel updates the registered gzip compressor to use the compression level specified (gzip.HuffmanOnly is not supported). NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. The error returned will be nil if the specified level
(level int)
| 56 | // |
| 57 | // The error returned will be nil if the specified level is valid. |
| 58 | func SetLevel(level int) error { |
| 59 | if level < gzip.DefaultCompression || level > gzip.BestCompression { |
| 60 | return fmt.Errorf("grpc: invalid gzip compression level: %d", level) |
| 61 | } |
| 62 | c := encoding.GetCompressor(Name).(*compressor) |
| 63 | c.poolCompressor.New = func() any { |
| 64 | w, err := gzip.NewWriterLevel(io.Discard, level) |
| 65 | if err != nil { |
| 66 | panic(err) |
| 67 | } |
| 68 | return &writer{Writer: w, pool: &c.poolCompressor} |
| 69 | } |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) { |
| 74 | z := c.poolCompressor.Get().(*writer) |
nothing calls this directly
no test coverage detected