Skip to main content

decompression_margin

Function decompression_margin 

Source
pub fn decompression_margin(src: &[u8]) -> Result<usize, FrameSizeError>
Expand description

Bytes the compressed input must trail the end of the output by for every frame in src to decode in place: the compressed data sits at the end of the output buffer and the decoder writes from its start. Backs the C ZSTD_decompressionMargin.

A frame costs its header, its checksum and three bytes per block, a skippable frame its whole length, and one largest block is added on top: a block may expand to its full size before its compressed bytes are consumed (upstream zstd_decompress.c:838-879).

§Errors

FrameSizeError on an unreadable header, truncation, or an invalid block.

use structured_zstd::encoding::{compress_slice_to_vec, CompressionLevel};
use structured_zstd::decoding::decompression_margin;
let frame = compress_slice_to_vec(&[9u8; 4096], CompressionLevel::Default);
assert!(decompression_margin(&frame).unwrap() >= frame.len().min(4096));