EncodeBest returns the encoded form of src. The returned slice may be a sub- slice of dst if dst was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. EncodeBest compresses as good as reasonably possible but with a big speed decrease. The dst and s
(dst, src []byte)
| 159 | // If you need to encode larger amounts of data, consider using |
| 160 | // the streaming interface which gives all of these features. |
| 161 | func EncodeBest(dst, src []byte) []byte { |
| 162 | if n := MaxEncodedLen(len(src)); n < 0 { |
| 163 | panic(ErrTooLarge) |
| 164 | } else if cap(dst) < n { |
| 165 | dst = make([]byte, n) |
| 166 | } else { |
| 167 | dst = dst[:n] |
| 168 | } |
| 169 | |
| 170 | // The block starts with the varint-encoded length of the decompressed bytes. |
| 171 | d := binary.PutUvarint(dst, uint64(len(src))) |
| 172 | |
| 173 | if len(src) == 0 { |
| 174 | return dst[:d] |
| 175 | } |
| 176 | if len(src) < minNonLiteralBlockSize { |
| 177 | d += emitLiteral(dst[d:], src) |
| 178 | return dst[:d] |
| 179 | } |
| 180 | n := encodeBlockBest(dst[d:], src, nil) |
| 181 | if n > 0 { |
| 182 | d += n |
| 183 | return dst[:d] |
| 184 | } |
| 185 | // Not compressible |
| 186 | d += emitLiteral(dst[d:], src) |
| 187 | return dst[:d] |
| 188 | } |
| 189 | |
| 190 | // EncodeSnappy returns the encoded form of src. The returned slice may be a sub- |
| 191 | // slice of dst if dst was large enough to hold the entire encoded block. |
searching dependent graphs…