(path, options)
| 317 | }); |
| 318 | |
| 319 | function WriteStream(path, options) { |
| 320 | if (!(this instanceof WriteStream)) |
| 321 | return new WriteStream(path, options); |
| 322 | |
| 323 | options = copyObject(getOptions(options, kEmptyObject)); |
| 324 | |
| 325 | // Only buffers are supported. |
| 326 | options.decodeStrings = true; |
| 327 | |
| 328 | if (options.fd == null) { |
| 329 | this.fd = null; |
| 330 | this[kFs] = options.fs || fs; |
| 331 | validateFunction(this[kFs].open, 'options.fs.open'); |
| 332 | |
| 333 | // Path will be ignored when fd is specified, so it can be falsy |
| 334 | this.path = toPathIfFileURL(path); |
| 335 | this.flags = options.flags === undefined ? 'w' : options.flags; |
| 336 | this.mode = options.mode === undefined ? 0o666 : options.mode; |
| 337 | |
| 338 | validatePath(this.path); |
| 339 | } else { |
| 340 | this.fd = getValidatedFd(importFd(this, options)); |
| 341 | } |
| 342 | |
| 343 | options.autoDestroy = options.autoClose === undefined ? |
| 344 | true : options.autoClose; |
| 345 | |
| 346 | if (!this[kFs].write && !this[kFs].writev) { |
| 347 | throw new ERR_INVALID_ARG_TYPE('options.fs.write', 'function', |
| 348 | this[kFs].write); |
| 349 | } |
| 350 | |
| 351 | if (this[kFs].write) { |
| 352 | validateFunction(this[kFs].write, 'options.fs.write'); |
| 353 | } |
| 354 | |
| 355 | if (this[kFs].writev) { |
| 356 | validateFunction(this[kFs].writev, 'options.fs.writev'); |
| 357 | } |
| 358 | |
| 359 | if (options.autoDestroy) { |
| 360 | validateFunction(this[kFs].close, 'options.fs.close'); |
| 361 | } |
| 362 | |
| 363 | this.flush = options.flush; |
| 364 | if (this.flush == null) { |
| 365 | this.flush = false; |
| 366 | } else { |
| 367 | validateBoolean(this.flush, 'options.flush'); |
| 368 | validateFunction(this[kFs].fsync, 'options.fs.fsync'); |
| 369 | } |
| 370 | |
| 371 | // It's enough to override either, in which case only one will be used. |
| 372 | if (!this[kFs].write) { |
| 373 | this._write = null; |
| 374 | } |
| 375 | if (!this[kFs].writev) { |
| 376 | this._writev = null; |
nothing calls this directly
no test coverage detected
searching dependent graphs…