tauri_plugin_printer/
fsys.rs

1
2use std::fs::{File, remove_file as rmf};
3
4use std::io::Write;
5use std::path::Path;
6use base64::{Engine as _, engine::{general_purpose}};
7
8
9pub fn create_file_from_base64(base64_string: &str, file_path: &str) -> Result<(), Box<dyn std::error::Error>> {
10    // Decode the base64 string into bytes
11    let mut buffer = Vec::<u8>::new();
12    // with the default engine
13    general_purpose::STANDARD
14        .decode_vec(base64_string, &mut buffer,).unwrap();
15
16    // Create a file at the specified path
17    let path = Path::new(file_path);
18    let mut file = File::create(&path)?;
19
20    // Write the decoded bytes to the file
21    file.write_all(&buffer)?;
22
23    Ok(())
24}
25
26pub fn remove_file (file_path: &str) -> Result<(), Box<dyn std::error::Error>> {
27    rmf(file_path)?;
28    Ok(())
29}