MCPcopy Create free account
hub / github.com/IBM/sarama / getDecoder

Function getDecoder

zstd.go:86–109  ·  view source on GitHub ↗
(params ZstdDecoderParams, maxDecodedSize int)

Source from the content-addressed store, hash-verified

84}
85
86func getDecoder(params ZstdDecoderParams, maxDecodedSize int) (*zstd.Decoder, error) {
87 key := zstdDecoderKey{params, maxDecodedSize}
88 if ret, ok := zstdDecMap.Load(key); ok {
89 return ret.(*zstd.Decoder), nil
90 }
91
92 zstdDecoderInitMu.Lock()
93 defer zstdDecoderInitMu.Unlock()
94
95 if ret, ok := zstdDecMap.Load(key); ok {
96 return ret.(*zstd.Decoder), nil
97 }
98
99 opts := []zstd.DOption{zstd.WithDecoderConcurrency(0)}
100 if maxDecodedSize > 0 {
101 opts = append(opts, zstd.WithDecoderMaxMemory(uint64(maxDecodedSize)))
102 }
103 dec, err := zstd.NewReader(nil, opts...)
104 if err != nil {
105 return nil, err
106 }
107 zstdDecMap.Store(key, dec)
108 return dec, nil
109}
110
111func zstdDecompress(params ZstdDecoderParams, dst, src []byte, maxDecodedSize int) ([]byte, error) {
112 dec, err := getDecoder(params, maxDecodedSize)

Callers 1

zstdDecompressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected