MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / load_bytes

Method load_bytes

src/storage.rs:89–117  ·  view source on GitHub ↗
(&self, path: &str)

Source from the content-addressed store, hash-verified

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"))]

Callers 1

load_stringMethod · 0.80

Calls 5

normalize_relative_pathFunction · 0.85
ply_storage_load_bytesFunction · 0.85
wait_for_responseFunction · 0.85
ensure_successFunction · 0.85
resolve_pathMethod · 0.80

Tested by

no test coverage detected