Skip to main content

Mountain/IPC/WindServiceHandlers/Model/
TextfileRead.rs

1#![allow(non_snake_case)]
2
3//! Read a text file from disk verbatim. Distinct from
4//! `ModelOpen` - this returns the bytes without registering a
5//! `DocumentStateDTO`. Used by tooling paths that want raw
6//! content (e.g. import resolvers, settings inspectors).
7
8use std::sync::Arc;
9
10use serde_json::Value;
11
12use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
13
14pub async fn TextfileRead(_runtime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15	let Path = Arguments
16		.first()
17		.and_then(|V| V.as_str())
18		.ok_or_else(|| "textFile:read requires path as first argument".to_string())?;
19
20	tokio::fs::read_to_string(Path)
21		.await
22		.map(Value::String)
23		.map_err(|Error| format!("textFile:read failed: {}", Error))
24}