(&self, path: &str, data: &[u8])
| 50 | } |
| 51 | |
| 52 | pub async fn save_bytes(&self, path: &str, data: &[u8]) -> Result<(), String> { |
| 53 | #[cfg(not(target_arch = "wasm32"))] |
| 54 | { |
| 55 | let full_path = self.resolve_path(path)?; |
| 56 | if let Some(parent) = full_path.parent() { |
| 57 | std::fs::create_dir_all(parent).map_err(|e| e.to_string())?; |
| 58 | } |
| 59 | std::fs::write(full_path, data).map_err(|e| e.to_string())?; |
| 60 | Ok(()) |
| 61 | } |
| 62 | |
| 63 | #[cfg(target_arch = "wasm32")] |
| 64 | { |
| 65 | let normalized_path = normalize_relative_path(path, "storage save path")?; |
| 66 | let op_id = unsafe { |
| 67 | ply_storage_save_bytes( |
| 68 | self.root_id, |
| 69 | JsObject::string(&normalized_path), |
| 70 | JsObject::buffer(data), |
| 71 | ) |
| 72 | }; |
| 73 | let result = wait_for_response(op_id).await?; |
| 74 | ensure_success(&result) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | pub async fn load_string(&self, path: &str) -> Result<Option<String>, String> { |
| 79 | match self.load_bytes(path).await? { |
no test coverage detected