Mountain/IPC/WindServiceHandlers/FileSystem/Native/
FileReadNative.rs1use serde_json::{Value, json};
10
11use crate::{IPC::WindServiceHandlers::Utilities::PathExtraction::Fn as extract_path_from_arg, dev_log};
12
13pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
14 let Path = extract_path_from_arg(Arguments.get(0).ok_or("Missing file path")?)?;
15
16 dev_log!("vfs-verbose", "readFile: {}", Path);
17
18 let Bytes = tokio::fs::read(&Path).await.map_err(|E| {
19 if E.kind() == std::io::ErrorKind::NotFound {
20 format!("readFile: {} resource not found (path: {})", E, Path)
21 } else {
22 format!("Failed to read file: {} (path: {})", E, Path)
23 }
24 })?;
25
26 dev_log!("vfs-verbose", "readFile OK: {} ({} bytes)", Path, Bytes.len());
27
28 let ByteArray:Vec<Value> = Bytes.iter().map(|B| json!(*B)).collect();
29
30 Ok(json!({ "buffer": ByteArray }))
31}