Mountain/IPC/WindServiceHandlers/FileSystem/Native/
FileReadNative.rs1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3use serde_json::{Value, json};
12
13use crate::{IPC::WindServiceHandlers::Utilities::PathExtraction::extract_path_from_arg, dev_log};
14
15pub async fn FileReadNative(Arguments:Vec<Value>) -> Result<Value, String> {
16 let Path = extract_path_from_arg(Arguments.get(0).ok_or("Missing file path")?)?;
17
18 dev_log!("vfs-verbose", "readFile: {}", Path);
19
20 let Bytes = tokio::fs::read(&Path)
21 .await
22 .map_err(|E| format!("Failed to read file: {} (path: {})", E, Path))?;
23
24 dev_log!("vfs-verbose", "readFile OK: {} ({} bytes)", Path, Bytes.len());
25
26 let ByteArray:Vec<Value> = Bytes.iter().map(|B| json!(*B)).collect();
27 Ok(json!({ "buffer": ByteArray }))
28}