Skip to content

Commit c5d24f4

Browse files
committed
lib: fix lacked resolve() in Blob.stream()'s source.pull()
Add lacked calling resolve() for finish ReadableStream source.pull(). Fixes: #48668 Fixes: #48916 Fixes: #48232 Refs: 8cc1438
1 parent 1eae568 commit c5d24f4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,29 @@ 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+
285+
(async () => {
286+
const file = new Blob(['<svg></svg>'], { type: 'image/svg+xml' });
287+
const url = URL.createObjectURL(file);
288+
const res = await fetch(url);
289+
const blob = await res.blob();
290+
assert.strictEqual(blob.size, 11);
291+
assert.strictEqual(blob.type, 'image/svg+xml');
292+
assert.strictEqual(await blob.text(), '<svg></svg>');
293+
})().then(common.mustCall());
294+
272295
(async () => {
273296
const b = new Blob(Array(10).fill('hello'));
274297
const stream = b.stream();

0 commit comments

Comments
 (0)