Skip to content

Commit dca8678

Browse files
bellbindRafaelGSS
authored andcommitted
lib: fix to add resolve() before return at Blob.stream()'s source.pull()
Add lacked calling resolve() for finish ReadableStream source.pull(). Fixes: #48668 Fixes: #48916 Fixes: #48232 Refs: 8cc1438 PR-URL: #48935 Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matthew Aitken <[email protected]>
1 parent 8380800 commit dca8678

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

lib/internal/blob.js

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

test/parallel/test-blob.js

+58
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,64 @@ 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 b = new Blob(['A', 'B', 'C']);
287+
const stream = b.stream();
288+
const chunks = [];
289+
const decoder = new TextDecoder();
290+
await stream.pipeTo(
291+
new WritableStream({
292+
write(chunk) {
293+
chunks.push(decoder.decode(chunk, { stream: true }));
294+
},
295+
})
296+
);
297+
assert.strictEqual(chunks.join(''), 'ABC');
298+
})().then(common.mustCall());
299+
300+
(async () => {
301+
// Ref: https://github.com/nodejs/node/issues/48668
302+
const chunks = [];
303+
const stream = new Blob(['Hello world']).stream();
304+
const decoder = new TextDecoder();
305+
await Promise.resolve();
306+
await stream.pipeTo(
307+
new WritableStream({
308+
write(chunk) {
309+
chunks.push(decoder.decode(chunk, { stream: true }));
310+
},
311+
})
312+
);
313+
assert.strictEqual(chunks.join(''), 'Hello world');
314+
})().then(common.mustCall());
315+
316+
(async () => {
317+
// Ref: https://github.com/nodejs/node/issues/48668
318+
if (common.hasCrypto) {
319+
// Can only do this test if we have node built with crypto
320+
const file = new Blob(['<svg></svg>'], { type: 'image/svg+xml' });
321+
const url = URL.createObjectURL(file);
322+
const res = await fetch(url);
323+
const blob = await res.blob();
324+
assert.strictEqual(blob.size, 11);
325+
assert.strictEqual(blob.type, 'image/svg+xml');
326+
assert.strictEqual(await blob.text(), '<svg></svg>');
327+
}
328+
})().then(common.mustCall());
329+
272330
(async () => {
273331
const b = new Blob(Array(10).fill('hello'));
274332
const stream = b.stream();

0 commit comments

Comments
 (0)