| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5828fad commit 253f5f4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -535,6 +535,16 @@ function fromWritable(writable, options = kNullPrototype) { | |||
| 535 | 535 | return (writable.writableLength ?? 0) >= hwm; | |
| 536 | 536 | } | |
| 537 | 537 | ||
| 538 | + function writeChunks(chunks) { | ||
| 539 | + let ok = true; | ||
| 540 | + for (let i = 0; i < chunks.length; i++) { | ||
| 541 | + const bytes = toUint8Array(chunks[i]); | ||
| 542 | + totalBytes += TypedArrayPrototypeGetByteLength(bytes); | ||
| 543 | + ok = writable.write(bytes); | ||
| 544 | + } | ||
| 545 | + return ok; | ||
| 546 | + } | ||
| 547 | + | ||
| 538 | 548 | const writer = { | |
| 539 | 549 | __proto__: null, | |
| 540 | 550 | ||
@@ -630,14 +640,18 @@ function fromWritable(writable, options = kNullPrototype) { | |||
| 630 | 640 | return PromiseResolve(); | |
| 631 | 641 | } | |
| 632 | 642 | ||
| 633 | - if (typeof writable.cork === 'function') writable.cork(); | ||
| 634 | 643 | let ok = true; | |
| 635 | - for (let i = 0; i < chunks.length; i++) { | ||
| 636 | - const bytes = toUint8Array(chunks[i]); | ||
| 637 | - totalBytes += TypedArrayPrototypeGetByteLength(bytes); | ||
| 638 | - ok = writable.write(bytes); | ||
| 644 | + if (typeof writable.cork === 'function' && | ||
| 645 | + typeof writable.uncork === 'function') { | ||
| 646 | + writable.cork(); | ||
| 647 | + try { | ||
| 648 | + ok = writeChunks(chunks); | ||
| 649 | + } finally { | ||
| 650 | + writable.uncork(); | ||
| 651 | + } | ||
| 652 | + } else { | ||
| 653 | + ok = writeChunks(chunks); | ||
| 639 | 654 | } | |
| 640 | - if (typeof writable.uncork === 'function') writable.uncork(); | ||
| 641 | 655 | ||
| 642 | 656 | if (ok) return PromiseResolve(); | |
| 643 | 657 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -550,6 +550,21 @@ function testWritevInvalidChunksType() { | |||
| 550 | 550 | ); | |
| 551 | 551 | } | |
| 552 | 552 | ||
| 553 | + // ============================================================================= | ||
| 554 | + // writev() uncorks when chunk validation throws | ||
| 555 | + // ============================================================================= | ||
| 556 | + | ||
| 557 | + function testWritevInvalidChunkUncorks() { | ||
| 558 | + const writable = new Writable({ write(chunk, enc, cb) { cb(); } }); | ||
| 559 | + const writer = fromWritable(writable); | ||
| 560 | + | ||
| 561 | + assert.throws( | ||
| 562 | + () => writer.writev([new Uint8Array([1]), 42]), | ||
| 563 | + { code: 'ERR_INVALID_ARG_TYPE' }, | ||
| 564 | + ); | ||
| 565 | + assert.strictEqual(writable.writableCorked, 0); | ||
| 566 | + } | ||
| 567 | + | ||
| 553 | 568 | // ============================================================================= | |
| 554 | 569 | // Cached writer: second call returns same instance | |
| 555 | 570 | // ============================================================================= | |
@@ -638,6 +653,7 @@ testDrainableNull(); | |||
| 638 | 653 | testDropOldestThrows(); | |
| 639 | 654 | testInvalidBackpressureThrows(); | |
| 640 | 655 | testWritevInvalidChunksType(); | |
| 656 | + testWritevInvalidChunkUncorks(); | ||
| 641 | 657 | testCachedWriter(); | |
| 642 | 658 | testObjectModeThrows(); | |
| 643 | 659 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments