Skip to main content

read_frame_content_size

Function read_frame_content_size 

Source
pub fn read_frame_content_size(
    src: &[u8],
) -> Result<FrameContentSize, ReadFrameHeaderError>
Expand description

Read the decompressed size a frame declares in its header, without decoding the frame body.

Parses only the leading frame header of src. Returns FrameContentSize::Known when the header carries an explicit Frame_Content_Size, or FrameContentSize::Unknown when it does not. This backs the C ZSTD_getFrameContentSize entry point, where the two variants map to a concrete size and ZSTD_CONTENTSIZE_UNKNOWN.

§Errors

Returns ReadFrameHeaderError when src is too short to hold a header, carries a bad magic number, or begins with a skippable frame.

use structured_zstd::encoding::{compress_slice_to_vec, CompressionLevel};
use structured_zstd::decoding::{read_frame_content_size, FrameContentSize};
let frame = compress_slice_to_vec(&[42u8; 100], CompressionLevel::Default);
assert_eq!(read_frame_content_size(&frame).unwrap(), FrameContentSize::Known(100));