(path, flags_, attrs, cb)
| 311 | return new WriteStream(this, path, options); |
| 312 | } |
| 313 | open(path, flags_, attrs, cb) { |
| 314 | if (this.server) |
| 315 | throw new Error('Client-only method called in server mode'); |
| 316 | |
| 317 | if (typeof attrs === 'function') { |
| 318 | cb = attrs; |
| 319 | attrs = undefined; |
| 320 | } |
| 321 | |
| 322 | const flags = (typeof flags_ === 'number' ? flags_ : stringToFlags(flags_)); |
| 323 | if (flags === null) |
| 324 | throw new Error(`Unknown flags string: ${flags_}`); |
| 325 | |
| 326 | let attrsFlags = 0; |
| 327 | let attrsLen = 0; |
| 328 | if (typeof attrs === 'string' || typeof attrs === 'number') |
| 329 | attrs = { mode: attrs }; |
| 330 | if (typeof attrs === 'object' && attrs !== null) { |
| 331 | attrs = attrsToBytes(attrs); |
| 332 | attrsFlags = attrs.flags; |
| 333 | attrsLen = attrs.nb; |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | uint32 id |
| 338 | string filename |
| 339 | uint32 pflags |
| 340 | ATTRS attrs |
| 341 | */ |
| 342 | const pathLen = Buffer.byteLength(path); |
| 343 | let p = 9; |
| 344 | const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + 4 + attrsLen); |
| 345 | |
| 346 | writeUInt32BE(buf, buf.length - 4, 0); |
| 347 | buf[4] = REQUEST.OPEN; |
| 348 | const reqid = this._writeReqid = (this._writeReqid + 1) & MAX_REQID; |
| 349 | writeUInt32BE(buf, reqid, 5); |
| 350 | |
| 351 | writeUInt32BE(buf, pathLen, p); |
| 352 | buf.utf8Write(path, p += 4, pathLen); |
| 353 | writeUInt32BE(buf, flags, p += pathLen); |
| 354 | writeUInt32BE(buf, attrsFlags, p += 4); |
| 355 | if (attrsLen) { |
| 356 | p += 4; |
| 357 | |
| 358 | if (attrsLen === ATTRS_BUF.length) |
| 359 | buf.set(ATTRS_BUF, p); |
| 360 | else |
| 361 | bufferCopy(ATTRS_BUF, buf, 0, attrsLen, p); |
| 362 | |
| 363 | p += attrsLen; |
| 364 | } |
| 365 | this._requests[reqid] = { cb }; |
| 366 | |
| 367 | const isBuffered = sendOrBuffer(this, buf); |
| 368 | this._debug && this._debug( |
| 369 | `SFTP: Outbound: ${isBuffered ? 'Buffered' : 'Sending'} OPEN` |
| 370 | ); |
no test coverage detected