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

Method Reset

zstd/decoder.go:166–234  ·  view source on GitHub ↗

Reset will reset the decoder the supplied stream after the current has finished processing. Note that this functionality cannot be used after Close has been called. Reset can be called with a nil reader to release references to the previous reader. After being called with a nil reader, no other oper

(r io.Reader)

Source from the content-addressed store, hash-verified

164// After being called with a nil reader, no other operations than Reset or DecodeAll or Close
165// should be used.
166func (d *Decoder) Reset(r io.Reader) error {
167 if d.current.err == ErrDecoderClosed {
168 return d.current.err
169 }
170
171 d.drainOutput()
172
173 d.syncStream.br.r = nil
174 if r == nil {
175 d.current.err = ErrDecoderNilInput
176 if len(d.current.b) > 0 {
177 d.current.b = d.current.b[:0]
178 }
179 d.current.flushed = true
180 return nil
181 }
182
183 // If bytes buffer and < 5MB, do sync decoding anyway.
184 if bb, ok := r.(byter); ok && bb.Len() < d.o.decodeBufsBelow && !d.o.limitToCap {
185 bb2 := bb
186 if debugDecoder {
187 println("*bytes.Buffer detected, doing sync decode, len:", bb.Len())
188 }
189 b := bb2.Bytes()
190 var dst []byte
191 if cap(d.syncStream.dstBuf) > 0 {
192 dst = d.syncStream.dstBuf[:0]
193 }
194
195 dst, err := d.DecodeAll(b, dst)
196 if err == nil {
197 err = io.EOF
198 }
199 // Save output buffer
200 d.syncStream.dstBuf = dst
201 d.current.b = dst
202 d.current.err = err
203 d.current.flushed = true
204 if debugDecoder {
205 println("sync decode to", len(dst), "bytes, err:", err)
206 }
207 return nil
208 }
209 // Remove current block.
210 d.stashDecoder()
211 d.current.decodeOutput = decodeOutput{}
212 d.current.err = nil
213 d.current.flushed = false
214 d.current.d = nil
215 d.syncStream.dstBuf = nil
216
217 // Ensure no-one else is still running...
218 d.streamWg.Wait()
219 if d.frame == nil {
220 d.frame = newFrameDec(d.o)
221 }
222
223 if d.o.concurrent == 1 {

Callers 2

NewReaderFunction · 0.95
ResetWithOptionsMethod · 0.95

Calls 9

drainOutputMethod · 0.95
DecodeAllMethod · 0.95
stashDecoderMethod · 0.95
startSyncDecoderMethod · 0.95
startStreamDecoderMethod · 0.95
printlnFunction · 0.85
newFrameDecFunction · 0.85
LenMethod · 0.80
BytesMethod · 0.65

Tested by

no test coverage detected