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

Method #flushBufferSync

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

Source from the content-addressed store, hash-verified

613 }
614
615 #flushBufferSync() {
616 if (this.#destroyed) {
617 throw new ERR_INVALID_STATE('Utf8Stream is destroyed');
618 }
619
620 if (this.#fd < 0) {
621 throw new ERR_INVALID_STATE('Invalid file descriptor');
622 }
623
624 if (!this.#writing && this.#writingBuf.length > 0) {
625 this.#bufs.unshift([this.#writingBuf]);
626 this.#writingBuf = kEmptyBuffer;
627 }
628
629 let buf = kEmptyBuffer;
630 while (this.#bufs.length || buf.length) {
631 if (buf.length <= 0) {
632 buf = mergeBuf(this.#bufs[0], this.#lens[0]);
633 }
634 try {
635 const n = this.#fs.writeSync(this.#fd, buf);
636 buf = buf.subarray(n);
637 this.#len = MathMax(this.#len - n, 0);
638 if (buf.length <= 0) {
639 this.#bufs.shift();
640 this.#lens.shift();
641 }
642 } catch (err) {
643 const shouldRetry = err.code === 'EAGAIN' || err.code === 'EBUSY';
644 if (shouldRetry && !this.#retryEAGAIN(err, buf.length, this.#len - buf.length)) {
645 throw err;
646 }
647
648 sleep(BUSY_WRITE_TIMEOUT);
649 }
650 }
651 }
652
653 #flushSyncUtf8() {
654 if (this.#destroyed) {

Callers 1

constructorMethod · 0.95

Calls 5

mergeBufFunction · 0.85
unshiftMethod · 0.80
sleepFunction · 0.50
writeSyncMethod · 0.45
shiftMethod · 0.45

Tested by

no test coverage detected