diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5dee648..cbf69f4 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -9,7 +9,8 @@ pub fn run() { .invoke_handler(tauri::generate_handler![ pdf::compile_pdf, project::read_file, - project::write_file + project::write_file, + project::write_bytes ]) .run(tauri::generate_context!()) .expect("error while running margin"); diff --git a/src-tauri/src/project.rs b/src-tauri/src/project.rs index 871c24b..3e7e856 100644 --- a/src-tauri/src/project.rs +++ b/src-tauri/src/project.rs @@ -1,3 +1,5 @@ +use base64::Engine; +use base64::engine::general_purpose::STANDARD; use std::fs; #[tauri::command] @@ -9,3 +11,9 @@ pub fn read_file(path: String) -> Result { pub fn write_file(path: String, contents: String) -> Result<(), String> { fs::write(&path, contents).map_err(|e| e.to_string()) } + +#[tauri::command] +pub fn write_bytes(path: String, data: String) -> Result<(), String> { + let bytes = STANDARD.decode(data.as_bytes()).map_err(|e| e.to_string())?; + fs::write(&path, bytes).map_err(|e| e.to_string()) +}