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

Method DecodeAll

zstd/decoder.go:319–410  ·  view source on GitHub ↗

DecodeAll allows stateless decoding of a blob of bytes. Output will be appended to dst, so if the destination size is known you can pre-allocate the destination slice to avoid allocations. DecodeAll can be used concurrently. The Decoder concurrency limits will be respected.

(input, dst []byte)

Source from the content-addressed store, hash-verified

317// DecodeAll can be used concurrently.
318// The Decoder concurrency limits will be respected.
319func (d *Decoder) DecodeAll(input, dst []byte) ([]byte, error) {
320 if d.decoders == nil {
321 return dst, ErrDecoderClosed
322 }
323
324 // Grab a block decoder and frame decoder.
325 block := <-d.decoders
326 frame := block.localFrame
327 initialSize := len(dst)
328 defer func() {
329 if debugDecoder {
330 printf("re-adding decoder: %p", block)
331 }
332 frame.rawInput = nil
333 frame.bBuf = nil
334 if frame.history.decoders.br != nil {
335 frame.history.decoders.br.in = nil
336 frame.history.decoders.br.cursor = 0
337 }
338 d.decoders <- block
339 }()
340 frame.bBuf = input
341
342 for {
343 frame.history.reset()
344 err := frame.reset(&frame.bBuf)
345 if err != nil {
346 if err == io.EOF {
347 if debugDecoder {
348 println("frame reset return EOF")
349 }
350 return dst, nil
351 }
352 return dst, err
353 }
354 if err = d.setDict(frame); err != nil {
355 return nil, err
356 }
357 if frame.WindowSize > d.o.maxWindowSize {
358 if debugDecoder {
359 println("window size exceeded:", frame.WindowSize, ">", d.o.maxWindowSize)
360 }
361 return dst, ErrWindowSizeExceeded
362 }
363 if frame.FrameContentSize != fcsUnknown {
364 if frame.FrameContentSize > d.o.maxDecodedSize-uint64(len(dst)-initialSize) {
365 if debugDecoder {
366 println("decoder size exceeded; fcs:", frame.FrameContentSize, "> mcs:", d.o.maxDecodedSize-uint64(len(dst)-initialSize), "len:", len(dst))
367 }
368 return dst, ErrDecoderSizeExceeded
369 }
370 if d.o.limitToCap && frame.FrameContentSize > uint64(cap(dst)-len(dst)) {
371 if debugDecoder {
372 println("decoder size exceeded; fcs:", frame.FrameContentSize, "> (cap-len)", cap(dst)-len(dst))
373 }
374 return dst, ErrDecoderSizeExceeded
375 }
376 if cap(dst)-len(dst) < int(frame.FrameContentSize) {

Callers 15

ResetMethod · 0.95
FuzzEncodingFunction · 0.95
TestHeader_DecodeFunction · 0.80
TestSnappy_ConvertSimpleFunction · 0.80
TestSnappy_ConvertXMLFunction · 0.80
TestSnappy_ConvertEnwik9Function · 0.80
FuzzDecodeAllFunction · 0.80
TestDecoder_SmallDictFunction · 0.80
TestEncoder_SmallDictFunction · 0.80

Calls 5

setDictMethod · 0.95
printfFunction · 0.85
printlnFunction · 0.85
runDecoderMethod · 0.80
resetMethod · 0.45

Tested by 15

FuzzEncodingFunction · 0.76
TestHeader_DecodeFunction · 0.64
TestSnappy_ConvertSimpleFunction · 0.64
TestSnappy_ConvertXMLFunction · 0.64
TestSnappy_ConvertEnwik9Function · 0.64
FuzzDecodeAllFunction · 0.64
TestDecoder_SmallDictFunction · 0.64
TestEncoder_SmallDictFunction · 0.64