Skip to main content

min_decoding_buffer_size

Function min_decoding_buffer_size 

Source
pub fn min_decoding_buffer_size(
    window_size: u64,
    frame_content_size: Option<u64>,
) -> Option<usize>
Expand description

Smallest output buffer a block-by-block decode of a frame can run in: the window, plus room for a block written after it and split literals, capped by the content size when the frame declares one. Backs the C ZSTD_decodingBufferSize_min; None when the result does not fit usize.

The two 32-byte terms are the over-copy allowance the sequence executor’s wide copies may write past a match (upstream WILDCOPY_OVERLENGTH, zstd_decompress.c:1965-1986).

use structured_zstd::decoding::min_decoding_buffer_size;
// A 1 MiB window with no declared content size.
assert_eq!(min_decoding_buffer_size(1 << 20, None), Some((1 << 20) + 2 * 131_072 + 64));
// A 1 KiB window holds no block over 1 KiB, so both block terms shrink.
assert_eq!(min_decoding_buffer_size(1 << 10, None), Some((1 << 10) + 2 * 1024 + 64));
// A frame whose whole content is smaller than that.
assert_eq!(min_decoding_buffer_size(1 << 20, Some(1000)), Some(1000));