| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -204,12 +204,12 @@ module.exports = function compose(...streams) { | |||
| 204 | 204 | try { | |
| 205 | 205 | const { value, done } = await reader.read(); | |
| 206 | 206 | ||
| 207 | - if (!d.push(value)) { | ||
| 207 | + if (done) { | ||
| 208 | + d.push(null); | ||
| 208 | 209 | return; | |
| 209 | 210 | } | |
| 210 | 211 | ||
| 211 | - if (done) { | ||
| 212 | - d.push(null); | ||
| 212 | + if (!d.push(value)) { | ||
| 213 | 213 | return; | |
| 214 | 214 | } | |
| 215 | 215 | } catch { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -537,3 +537,24 @@ const assert = require('assert'); | |||
| 537 | 537 | assert.strictEqual(duplex.destroyed, true); | |
| 538 | 538 | ||
| 539 | 539 | } | |
| 540 | + | ||
| 541 | + // Regression test: compose with a web TransformStream tail must always emit | ||
| 542 | + // null (EOF) when the source finishes. The done check must precede the | ||
| 543 | + // backpressure check in the reader.read() loop; otherwise push(null) can be | ||
| 544 | + // skipped if canPushMore() returns false on the final done:true read. | ||
| 545 | + { | ||
| 546 | + const { TransformStream } = globalThis; | ||
| 547 | + const { Readable } = require('stream'); | ||
| 548 | + | ||
| 549 | + // A web TransformStream as the tail exercises the isWebStream code path | ||
| 550 | + // in compose that loops over reader.read() results. | ||
| 551 | + const ts = new TransformStream(); | ||
| 552 | + const src = Readable.from(['hello', ' ', 'world']); | ||
| 553 | + const composed = compose(src, ts); | ||
| 554 | + | ||
| 555 | + let result = ''; | ||
| 556 | + composed.on('data', (chunk) => { result += Buffer.from(chunk).toString(); }); | ||
| 557 | + composed.on('end', common.mustCall(() => { | ||
| 558 | + assert.strictEqual(result, 'hello world'); | ||
| 559 | + })); | ||
| 560 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments