()
| 651 | } |
| 652 | |
| 653 | #flushSyncUtf8() { |
| 654 | if (this.#destroyed) { |
| 655 | throw new ERR_INVALID_STATE('Utf8Stream is destroyed'); |
| 656 | } |
| 657 | |
| 658 | if (this.#fd < 0) { |
| 659 | throw new ERR_INVALID_STATE('Invalid file descriptor'); |
| 660 | } |
| 661 | |
| 662 | if (!this.#writing && this.#writingBuf.length > 0) { |
| 663 | this.#bufs.unshift(this.#writingBuf); |
| 664 | this.#writingBuf = ''; |
| 665 | } |
| 666 | |
| 667 | let buf = ''; |
| 668 | while (this.#bufs.length || buf) { |
| 669 | if (buf.length <= 0) { |
| 670 | buf = this.#bufs[0]; |
| 671 | } |
| 672 | try { |
| 673 | const n = this.#fs.writeSync(this.#fd, buf, 'utf8'); |
| 674 | const releasedBufObj = releaseWritingBuf(buf, this.#len, n); |
| 675 | buf = releasedBufObj.writingBuf; |
| 676 | this.#len = releasedBufObj.len; |
| 677 | if (buf.length <= 0) { |
| 678 | this.#bufs.shift(); |
| 679 | } |
| 680 | } catch (err) { |
| 681 | const shouldRetry = err.code === 'EAGAIN' || err.code === 'EBUSY'; |
| 682 | if (shouldRetry && !this.#retryEAGAIN(err, buf.length, this.#len - buf.length)) { |
| 683 | throw err; |
| 684 | } |
| 685 | |
| 686 | sleep(BUSY_WRITE_TIMEOUT); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | try { |
| 691 | this.#fs.fsyncSync(this.#fd); |
| 692 | } catch { |
| 693 | // Skip the error. The fd might not support fsync. |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | #callFlushCallbackOnDrain(cb) { |
| 698 | this.#flushPending = true; |
no test coverage detected