MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / readFile

Method readFile

src/fileSystem/sftp.js:194–227  ·  view source on GitHub ↗

* Read the file from server

()

Source from the content-addressed store, hash-verified

192 * Read the file from server
193 */
194 readFile() {
195 const filename = this.#path;
196 const localFilename = this.#getLocalname(filename);
197 return new Promise((resolve, reject) => {
198 sftp.isConnected((connectionID) => {
199 (async () => {
200 if (this.#notConnected(connectionID)) {
201 try {
202 await this.connect();
203 } catch (error) {
204 reject(error);
205 return;
206 }
207 }
208
209 sftp.getFile(
210 this.#safeName(filename),
211 localFilename,
212 async () => {
213 try {
214 const data = await internalFs.readFile(localFilename);
215 resolve(data);
216 } catch (error) {
217 reject(error);
218 }
219 },
220 (err) => {
221 reject(err);
222 },
223 );
224 })();
225 });
226 });
227 }
228
229 async copyTo(dest) {
230 const src = this.#path;

Callers 1

readFileFunction · 0.45

Calls 7

#getLocalnameMethod · 0.95
#notConnectedMethod · 0.95
connectMethod · 0.95
#safeNameMethod · 0.95
resolveFunction · 0.85
isConnectedMethod · 0.65
getFileMethod · 0.65

Tested by

no test coverage detected