Skip to main content

compress_best

Function compress_best 

Source
pub fn compress_best(body: &[u8]) -> Vec<u8> ⓘ
Expand description

Compress body with the SMALLEST of the built-in codecs (deflate / lz4 / zstd), self-describing: byte 0 is the codec tag (0=deflate, 1=lz4, 2=zstd, 3=stored raw), the rest is the body. When nothing shrinks the input it is stored raw under tag 3 — so this NEVER grows a payload by more than the single tag byte (the discipline for already-encoded / already-encrypted data, which does not compress). Compress-BEFORE-encrypt is the intended use: ciphertext is incompressible, so the squeeze must happen on the plaintext frame. The inverse is decompress_any.