INNER CODE UNIT · Rust
load_resource
mouseart2025/AI-Reader-V2 · frontend/src-tauri/src/lib.rs:253
fn load_resource(app: tauri::AppHandle, path: String) -> Result<String, String> {
let resource_path = app
.path()
.resolve(&path, tauri::path::BaseDirectory::Resource)
.map_err(|e| format!("路径解析失败: {e}"))?;
let bytes = std::fs::read(&resource_path)
.map_err(|e| format!("读取文件失败: {} — {e}", resource_path.display()))?;
decompress_if_gzip(bytes)
}
/// Read a file from an absolute path (for user-imported data outside bundle)
#[tauri::command]
fn load_file_absolute(path: String) -> Result<String, String> {
let bytes = std::fs::read(&path)
.map_err(|e| format!("读取文件失败: {path} — {e}"))?;