Skip to content

Commit 5a661b9

Browse files
committed
lib/internal/blob.js: fix Blob.stream() for nodejs#48668 nodejs#48916
Add lacked calling resolve() for finish ReadableStream source.pull(). Fixes: nodejs#48668 Fixes: nodejs#48916 Fixes: nodejs#48232 Refs: 8cc1438
1 parent 1eae568 commit 5a661b9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/internal/blob.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ class Blob {
360360
queueMicrotask(() => {
361361
if (c.desiredSize <= 0) {
362362
// A manual backpressure check.
363+
if (this.pendingPulls.length !== 0) {
364+
// A case of waiting pull finished (= not yet canceled)
365+
const pending = this.pendingPulls.shift();
366+
pending.resolve();
367+
}
363368
return;
364369
}
365370
readNext();

test/parallel/test-blob.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ assert.throws(() => new Blob({}), {
269269
reader.closed.then(common.mustCall());
270270
})().then(common.mustCall());
271271

272+
(async () => {
273+
const b = new Blob(['A', 'B', 'C']);
274+
const stream = b.stream();
275+
const chunks = [];
276+
const decoder = new TextDecoder();
277+
await stream.pipeTo(new WritableStream({
278+
write(chunk) {
279+
chunks.push(decoder.decode(chunk, { stream: true }));
280+
}
281+
}));
282+
assert.strictEqual(chunks.join(''), 'ABC');
283+
})().then(common.mustCall());
284+
272285
(async () => {
273286
const b = new Blob(Array(10).fill('hello'));
274287
const stream = b.stream();

0 commit comments

Comments
 (0)