MCPcopy Create free account
hub / github.com/mscdex/ssh2 / fastXfer

Function fastXfer

lib/protocol/SFTP.js:2185–2391  ·  view source on GitHub ↗
(src, dst, srcPath, dstPath, opts, cb)

Source from the content-addressed store, hash-verified

2183}
2184
2185function fastXfer(src, dst, srcPath, dstPath, opts, cb) {
2186 let concurrency = 64;
2187 let chunkSize = 32768;
2188 let onstep;
2189 let mode;
2190 let fileSize;
2191
2192 if (typeof opts === 'function') {
2193 cb = opts;
2194 } else if (typeof opts === 'object' && opts !== null) {
2195 if (typeof opts.concurrency === 'number'
2196 && opts.concurrency > 0
2197 && !isNaN(opts.concurrency)) {
2198 concurrency = opts.concurrency;
2199 }
2200 if (typeof opts.chunkSize === 'number'
2201 && opts.chunkSize > 0
2202 && !isNaN(opts.chunkSize)) {
2203 chunkSize = opts.chunkSize;
2204 }
2205 if (typeof opts.fileSize === 'number'
2206 && opts.fileSize > 0
2207 && !isNaN(opts.fileSize)) {
2208 fileSize = opts.fileSize;
2209 }
2210 if (typeof opts.step === 'function')
2211 onstep = opts.step;
2212
2213 if (typeof opts.mode === 'string' || typeof opts.mode === 'number')
2214 mode = modeNum(opts.mode);
2215 }
2216
2217 // Internal state variables
2218 let fsize;
2219 let pdst = 0;
2220 let total = 0;
2221 let hadError = false;
2222 let srcHandle;
2223 let dstHandle;
2224 let readbuf;
2225 let bufsize = chunkSize * concurrency;
2226
2227 function onerror(err) {
2228 if (hadError)
2229 return;
2230
2231 hadError = true;
2232
2233 let left = 0;
2234 let cbfinal;
2235
2236 if (srcHandle || dstHandle) {
2237 cbfinal = () => {
2238 if (--left === 0)
2239 cb(err);
2240 };
2241 if (srcHandle && (src === fs || src.outgoing.state === 'open'))
2242 ++left;

Callers 2

fastGetMethod · 0.85
fastPutMethod · 0.85

Calls 5

modeNumFunction · 0.85
onerrorFunction · 0.85
tryStatFunction · 0.85
openMethod · 0.80
fstatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…