MCPcopy Create free account
hub / github.com/BitVM/BitVM / get_object

Method get_object

bridge/src/client/data_store/sftp.rs:74–107  ·  view source on GitHub ↗
(&self, key: &str, file_path: Option<&str>)

Source from the content-addressed store, hash-verified

72 }
73
74 async fn get_object(&self, key: &str, file_path: Option<&str>) -> Result<Vec<u8>, String> {
75 let mut buffer: Vec<u8> = vec![];
76
77 match connect(&self.credentials).await {
78 Ok(sftp) => {
79 let mut full_filename = key.to_string();
80 if file_path.is_some() {
81 full_filename = format!("{}/{}", file_path.unwrap(), key);
82 }
83 match sftp.open(full_filename).await.map(TokioCompatFile::from) {
84 Ok(_file) => {
85 let mut file = Box::pin(_file);
86 let result = file.read_to_end(&mut buffer).await;
87 drop(file);
88 match result {
89 Ok(_) => {
90 disconnect(sftp).await;
91 Ok(buffer)
92 }
93 Err(err) => {
94 disconnect(sftp).await;
95 Err(format!("Unable to get {}: {}", key, err))
96 }
97 }
98 }
99 Err(err) => {
100 disconnect(sftp).await;
101 Err(format!("Unable to get {}: {}", key, err))
102 }
103 }
104 }
105 Err(err) => Err(format!("Unable to get {}: {}", key, err)),
106 }
107 }
108
109 async fn upload_object(
110 &self,

Callers 2

fetch_objectMethod · 0.45

Calls 2

connectFunction · 0.85
disconnectFunction · 0.70

Tested by

no test coverage detected