MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / decompress_native

Function decompress_native

nodedb-codec/src/zstd_codec.rs:105–126  ·  view source on GitHub ↗
(frame: &[u8], expected_size: usize)

Source from the content-addressed store, hash-verified

103
104#[cfg(not(target_arch = "wasm32"))]
105fn decompress_native(frame: &[u8], expected_size: usize) -> Result<Vec<u8>, CodecError> {
106 let mut output = Vec::with_capacity(expected_size);
107 let mut decoder = zstd::Decoder::new(std::io::Cursor::new(frame)).map_err(|e| {
108 CodecError::DecompressFailed {
109 detail: format!("zstd decoder init: {e}"),
110 }
111 })?;
112 std::io::copy(&mut decoder, &mut output).map_err(|e| CodecError::DecompressFailed {
113 detail: format!("zstd decompress: {e}"),
114 })?;
115
116 if output.len() != expected_size {
117 return Err(CodecError::Corrupt {
118 detail: format!(
119 "zstd size mismatch: expected {expected_size}, got {}",
120 output.len()
121 ),
122 });
123 }
124
125 Ok(output)
126}
127
128// WASM: use ruzstd for decompression. Compression on WASM uses a simple
129// fallback (ruzstd is decode-only; if full Zstd encoding is needed on WASM,

Callers 1

decodeFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected