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

Method save_bytes

src/storage.rs:52–76  ·  view source on GitHub ↗
(&self, path: &str, data: &[u8])

Source from the content-addressed store, hash-verified

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? {

Callers 1

save_stringMethod · 0.80

Calls 5

normalize_relative_pathFunction · 0.85
ply_storage_save_bytesFunction · 0.85
wait_for_responseFunction · 0.85
ensure_successFunction · 0.85
resolve_pathMethod · 0.80

Tested by

no test coverage detected