| 2391 | } |
| 2392 | |
| 2393 | function writeAll(sftp, handle, buffer, offset, length, position, callback_) { |
| 2394 | const callback = (typeof callback_ === 'function' ? callback_ : undefined); |
| 2395 | |
| 2396 | sftp.write(handle, |
| 2397 | buffer, |
| 2398 | offset, |
| 2399 | length, |
| 2400 | position, |
| 2401 | (writeErr, written) => { |
| 2402 | if (writeErr) { |
| 2403 | return sftp.close(handle, () => { |
| 2404 | callback && callback(writeErr); |
| 2405 | }); |
| 2406 | } |
| 2407 | if (written === length) { |
| 2408 | sftp.close(handle, callback); |
| 2409 | } else { |
| 2410 | offset += written; |
| 2411 | length -= written; |
| 2412 | position += written; |
| 2413 | writeAll(sftp, handle, buffer, offset, length, position, callback); |
| 2414 | } |
| 2415 | }); |
| 2416 | } |
| 2417 | |
| 2418 | class Stats { |
| 2419 | constructor(initial) { |