Mountain/IPC/WindServiceHandlers/FileSystem/Managed/
FileReadBinary.rs1use std::{path::PathBuf, sync::Arc};
6
7use CommonLibrary::{Environment::Requires::Requires, FileSystem::FileSystemReader::FileSystemReader};
8use serde_json::{Value, json};
9
10use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
11
12pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
13 let path = Arguments
14 .get(0)
15 .ok_or("Missing file path".to_string())?
16 .as_str()
17 .ok_or("File path must be a string".to_string())?;
18
19 let provider:Arc<dyn FileSystemReader> = RunTime.Environment.Require();
20
21 let content = provider
22 .ReadFile(&PathBuf::from(path))
23 .await
24 .map_err(|Error| format!("Failed to read binary file: {}", Error))?;
25
26 dev_log!("vfs-verbose", "readBinary: {} ({} bytes)", path, content.len());
27
28 Ok(json!(content))
29}