| 535 | } |
| 536 | |
| 537 | #actualClose() { |
| 538 | if (this.#fd === -1) { |
| 539 | this.once('ready', () => this.#actualClose()); |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | if (this.#periodicFlushTimer !== undefined) { |
| 544 | clearInterval(this.#periodicFlushTimer); |
| 545 | } |
| 546 | |
| 547 | this.#destroyed = true; |
| 548 | this.#bufs = []; |
| 549 | this.#lens = []; |
| 550 | |
| 551 | const done = (err) => { |
| 552 | if (err) { |
| 553 | this.emit('error', err); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | if (this.#ending && !this.#writing) { |
| 558 | this.emit('finish'); |
| 559 | } |
| 560 | this.emit('close'); |
| 561 | }; |
| 562 | |
| 563 | const closeWrapped = () => { |
| 564 | // We skip errors in fsync |
| 565 | if (this.#fd !== 1 && this.#fd !== 2) { |
| 566 | this.#fs.close(this.#fd, done); |
| 567 | } else { |
| 568 | done(); |
| 569 | } |
| 570 | }; |
| 571 | |
| 572 | try { |
| 573 | this.#fs.fsync(this.#fd, closeWrapped); |
| 574 | } catch { |
| 575 | // Intentionally empty. |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | #actualWriteBuffer() { |
| 580 | this.#writing = true; |