mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
feat(io): add write_bytes command for binary exports
This commit is contained in:
1 parent
aedf8b8a63
commit
4443eda401
2 files changed
+10
-1
No files matched your search
@@ -9,7 +9,8 @@ pub fn run() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
pdf::compile_pdf,
|
pdf::compile_pdf,
|
||||||
project::read_file,
|
project::read_file,
|
||||||
project::write_file
|
project::write_file,
|
||||||
|
project::write_bytes
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running margin");
|
.expect("error while running margin");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -9,3 +11,9 @@ pub fn read_file(path: String) -> Result<String, String> {
|
|||||||
pub fn write_file(path: String, contents: String) -> Result<(), String> {
|
pub fn write_file(path: String, contents: String) -> Result<(), String> {
|
||||||
fs::write(&path, contents).map_err(|e| e.to_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())
|
||||||
|
}
|
||||||
Reference in new issue
Block a user