1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| _put(lPath, rPath, opts, addListeners = true) { let listeners, wtr, rdr; return new Promise((resolve, reject) => { if (addListeners) { listeners = addTempListeners(this, '_put', reject); } opts = { readStreamOptions: { ...opts?.readStreamOptions, autoClose: true }, writeStreamOptions: { ...opts?.writeStreamOptions, autoClose: true }, pipeOptions: { ...opts?.pipeOptions, end: true }, }; if (haveConnection(this, '_put', reject)) { wtr = this.sftp.createWriteStream(rPath, opts.writeStreamOptions); ... if (lPath instanceof Buffer) { this.debugMsg('put source is a buffer'); wtr.end(lPath); } else { rdr = typeof lPath === 'string' ? fs.createReadStream(lPath, opts.readStreamOptions) : lPath; ... rdr.pipe(wtr, opts.pipeOptions); } } }).finally(() => { if (addListeners) { removeTempListeners(this, listeners, '_put'); } }); }
|