| 103 | |
| 104 | #[cfg(not(target_arch = "wasm32"))] |
| 105 | fn 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, |