EncodeSnappyBest 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. The output is Snappy compatible and will likely decompress faster. The dst and src must not
(dst, src []byte)
| 290 | // If you need to encode larger amounts of data, consider using |
| 291 | // the streaming interface which gives all of these features. |
| 292 | func EncodeSnappyBest(dst, src []byte) []byte { |
| 293 | if n := MaxEncodedLen(len(src)); n < 0 { |
| 294 | panic(ErrTooLarge) |
| 295 | } else if cap(dst) < n { |
| 296 | dst = make([]byte, n) |
| 297 | } else { |
| 298 | dst = dst[:n] |
| 299 | } |
| 300 | |
| 301 | // The block starts with the varint-encoded length of the decompressed bytes. |
| 302 | d := binary.PutUvarint(dst, uint64(len(src))) |
| 303 | |
| 304 | if len(src) == 0 { |
| 305 | return dst[:d] |
| 306 | } |
| 307 | if len(src) < minNonLiteralBlockSize { |
| 308 | d += emitLiteral(dst[d:], src) |
| 309 | return dst[:d] |
| 310 | } |
| 311 | |
| 312 | n := encodeBlockBestSnappy(dst[d:], src) |
| 313 | if n > 0 { |
| 314 | d += n |
| 315 | return dst[:d] |
| 316 | } |
| 317 | // Not compressible |
| 318 | d += emitLiteral(dst[d:], src) |
| 319 | return dst[:d] |
| 320 | } |
| 321 | |
| 322 | // ConcatBlocks will concatenate the supplied blocks and append them to the supplied destination. |
| 323 | // If the destination is nil or too small, a new will be allocated. |
searching dependent graphs…