Skip to main content

decode_if_compressed

Function decode_if_compressed 

Source
pub fn decode_if_compressed(bytes: &[u8]) -> Cow<'_, [u8]>
Expand description

Inspect bytes. If the magic header is present and decodes cleanly, return the decompressed payload as Cow::Owned. Otherwise return Cow::Borrowed(bytes) so the no-compression hot path stays allocation-free.

A corrupted magic header (right prefix, wrong codec byte, garbage length) is treated as “not compressed” and the original bytes are returned. This matches the “graceful fallback” requirement: a single torn blob in a bucket should not break the whole load path.