Include content size in Zstd frame header

Figma requires the Zstd content size to be present in the frame header.
Use zstd::Encoder with include_contentsize(true) instead of encode_all.
This commit is contained in:
Danila Poyarkov 2026-02-28 16:03:58 +03:00
parent 2b91f51de8
commit 5aae8d01fc

View file

@ -5,7 +5,13 @@ use tauri::{
#[tauri::command]
fn zstd_compress(data: Vec<u8>) -> Result<Vec<u8>, String> {
zstd::encode_all(data.as_slice(), 3).map_err(|e| e.to_string())
use std::io::Write;
let mut encoder = zstd::Encoder::new(Vec::new(), 3).map_err(|e| e.to_string())?;
encoder
.include_contentsize(true)
.map_err(|e| e.to_string())?;
encoder.write_all(&data).map_err(|e| e.to_string())?;
encoder.finish().map_err(|e| e.to_string())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]