Skip to main content

Mountain/IPC/WindServiceHandlers/FileSystem/Managed/
FileRead.rs

1//! Legacy wire method `file:read` (UTF-8 content). Routes via RunTime's
2//! `FileSystemReader` trait. Not currently wired into dispatch (native
3//! variant handles `file:read`); kept for future per-provider routing.
4
5use 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 file: {}", Error))?;
25
26	dev_log!("vfs-verbose", "read: {} ({} bytes)", path, content.len());
27
28	Ok(json!(content))
29}