Decode returns the decoded form of src or error, given expected compression type. The buf is used as a buffer for the returned decoded entry, and it must not overlap with src. It is valid to pass a nil buf.
(t Type, src, buf []byte)
| 110 | // The buf is used as a buffer for the returned decoded entry, and it must not |
| 111 | // overlap with src. It is valid to pass a nil buf. |
| 112 | func (d *Decoder) Decode(t Type, src, buf []byte) (_ []byte, err error) { |
| 113 | switch { |
| 114 | case len(src) == 0, t == "", t == None: |
| 115 | return src, nil |
| 116 | case t == Snappy: |
| 117 | // The snappy library uses `len` to calculate if we need a new buffer. |
| 118 | // In order to allocate as few buffers as possible make the length |
| 119 | // equal to the capacity. |
| 120 | buf = buf[:cap(buf)] |
| 121 | return snappy.Decode(buf, src) |
| 122 | case t == Zstd: |
| 123 | if d == nil { |
| 124 | return nil, errors.New("zstd requested but Decoder was not initialized with NewDecoder()") |
| 125 | } |
| 126 | return d.r.DecodeAll(src, buf[:0]) |
| 127 | default: |
| 128 | return nil, fmt.Errorf("unsupported compression type: %s", t) |
| 129 | } |
| 130 | } |
no outgoing calls