MCPcopy
hub / github.com/grpc/grpc-go / SetLevel

Function SetLevel

encoding/gzip/gzip.go:58–71  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

56//
57// The error returned will be nil if the specified level is valid.
58func 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
73func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) {
74 z := c.poolCompressor.Get().(*writer)

Callers

nothing calls this directly

Calls 2

GetCompressorFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected