MCPcopy Index your code
hub / github.com/nodejs/node / #openFile

Method #openFile

lib/internal/streams/fast-utf8-stream.js:456–528  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

454 }
455
456 #openFile(file) {
457 this.#opening = true;
458 this.#writing = true;
459 this.#asyncDrainScheduled = false;
460
461 // NOTE: 'error' and 'ready' events emitted below only relevant when sonic.sync===false
462 // for sync mode, there is no way to add a listener that will receive these
463
464 const fileOpened = (err, fd) => {
465 if (err) {
466 this.#reopening = false;
467 this.#writing = false;
468 this.#opening = false;
469
470 if (this.#sync) {
471 process.nextTick(() => {
472 if (this.listenerCount('error') > 0) {
473 this.emit('error', err);
474 }
475 });
476 } else {
477 this.emit('error', err);
478 }
479 return;
480 }
481
482 const reopening = this.#reopening;
483
484 this.#fd = fd;
485 this.#file = file;
486 this.#reopening = false;
487 this.#opening = false;
488 this.#writing = false;
489
490 if (this.#sync) {
491 process.nextTick(() => this.emit('ready'));
492 } else {
493 this.emit('ready');
494 }
495
496 if (this.#destroyed) {
497 return;
498 }
499
500 // start
501 if ((!this.#writing && this.#len > this.#minLength) || this.#flushPending) {
502 this.#actualWrite();
503 } else if (reopening) {
504 process.nextTick(() => this.emit('drain'));
505 }
506 };
507
508 const flags = this.#append ? 'a' : 'w';
509 const mode = this.#mode;
510
511 if (this.#sync) {
512 try {
513 if (this.#mkdir) this.#fs.mkdirSync(path.dirname(file), { recursive: true });

Callers 2

constructorMethod · 0.95
reopenMethod · 0.95

Calls 4

openMethod · 0.65
mkdirSyncMethod · 0.45
openSyncMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected