INNER CODE UNIT · Rust
decompress_zstd_bounded_inner
Augani/dory · dory-core/ffi/src/lib.rs:91
fn decompress_zstd_bounded_inner(
body: &[u8],
maximum_output_bytes: u64,
) -> Result<Vec<u8>, String> {
use std::io::Read;
if body.is_empty() {
return Err("compressed payload is empty".to_string());
}
if maximum_output_bytes == 0 || maximum_output_bytes > MAXIMUM_ZSTD_OUTPUT_BYTES {
return Err(format!(
"maximum output must be between 1 and {MAXIMUM_ZSTD_OUTPUT_BYTES} bytes"
));
}
let cursor = std::io::Cursor::new(body);
let mut decoder = zstd::stream::read::Decoder::new(cursor)
.map_err(|error| format!("invalid zstd frame: {error}"))?;