(&self, path: &str)
| 87 | } |
| 88 | |
| 89 | pub async fn load_bytes(&self, path: &str) -> Result<Option<Vec<u8>>, String> { |
| 90 | #[cfg(not(target_arch = "wasm32"))] |
| 91 | { |
| 92 | let full_path = self.resolve_path(path)?; |
| 93 | match std::fs::read(full_path) { |
| 94 | Ok(bytes) => Ok(Some(bytes)), |
| 95 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None), |
| 96 | Err(error) => Err(error.to_string()), |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #[cfg(target_arch = "wasm32")] |
| 101 | { |
| 102 | let normalized_path = normalize_relative_path(path, "storage load path")?; |
| 103 | let op_id = unsafe { |
| 104 | ply_storage_load_bytes(self.root_id, JsObject::string(&normalized_path)) |
| 105 | }; |
| 106 | let result = wait_for_response(op_id).await?; |
| 107 | ensure_success(&result)?; |
| 108 | |
| 109 | if result.field_u32("exists") == 0 { |
| 110 | return Ok(None); |
| 111 | } |
| 112 | |
| 113 | let mut bytes = Vec::new(); |
| 114 | result.field("data").to_byte_buffer(&mut bytes); |
| 115 | Ok(Some(bytes)) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | pub async fn remove(&self, path: &str) -> Result<(), String> { |
| 120 | #[cfg(not(target_arch = "wasm32"))] |
no test coverage detected