MCPcopy
hub / github.com/klauspost/compress / NewReader

Function NewReader

zstd/decoder.go:84–118  ·  view source on GitHub ↗

NewReader creates a new decoder. A nil Reader can be provided in which case Reset can be used to start a decode. A Decoder can be used in two modes: 1) As a stream, or 2) For stateless decoding using DecodeAll. Only a single stream can be decoded concurrently, but the same decoder can run multipl

(r io.Reader, opts ...DOption)

Source from the content-addressed store, hash-verified

82// The Reset function can be used to initiate a new stream, which will considerably
83// reduce the allocations normally caused by NewReader.
84func NewReader(r io.Reader, opts ...DOption) (*Decoder, error) {
85 initPredefined()
86 var d Decoder
87 d.o.setDefault()
88 for _, o := range opts {
89 err := o(&d.o)
90 if err != nil {
91 return nil, err
92 }
93 }
94 d.current.crc = xxhash.New()
95 d.current.flushed = true
96
97 if r == nil {
98 d.current.err = ErrDecoderNilInput
99 }
100
101 // Initialize dict map if needed.
102 if d.o.dicts == nil {
103 d.o.dicts = make(map[uint32]*dict)
104 }
105
106 // Create decoders
107 d.decoders = make(chan *blockDec, d.o.concurrent)
108 for i := 0; i < d.o.concurrent; i++ {
109 dec := newBlockDec(d.o.lowMem)
110 dec.localFrame = newFrameDec(d.o)
111 d.decoders <- dec
112 }
113
114 if r == nil {
115 return &d, nil
116 }
117 return &d, d.Reset(r)
118}
119
120// Read bytes from the decompressed stream into p.
121// Returns the number of bytes read and any error that occurred.

Callers 15

ReadMethod · 0.92
TestZstdHandlerFunction · 0.92
TestZstdLevelsFunction · 0.92
TestZstdRandomJitterFunction · 0.92
TestDataRoundtripsFunction · 0.92
TestHeader_DecodeFunction · 0.70
TestSnappy_ConvertSimpleFunction · 0.70
TestSnappy_ConvertXMLFunction · 0.70
TestSnappy_ConvertEnwik9Function · 0.70

Calls 6

ResetMethod · 0.95
NewFunction · 0.92
initPredefinedFunction · 0.85
newBlockDecFunction · 0.85
newFrameDecFunction · 0.85
setDefaultMethod · 0.45

Tested by 15

TestZstdHandlerFunction · 0.74
TestZstdLevelsFunction · 0.74
TestZstdRandomJitterFunction · 0.74
TestDataRoundtripsFunction · 0.74
TestHeader_DecodeFunction · 0.56
TestSnappy_ConvertSimpleFunction · 0.56
TestSnappy_ConvertXMLFunction · 0.56
TestSnappy_ConvertEnwik9Function · 0.56
BenchmarkSnappy_Enwik9Function · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…