Skip to content

Commit

Permalink
ib: fix Blob.stream() for nodejs#48668 nodejs#48916
Browse files Browse the repository at this point in the history
Add lacked calling resolve() for finish ReadableStream source.pull().

Fixes: nodejs#48668
Fixes: nodejs#48916
Fixes: nodejs#48232
Refs: 8cc1438
  • Loading branch information
bellbind committed Jul 27, 2023
1 parent 1eae568 commit a3af3cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ class Blob {
queueMicrotask(() => {
if (c.desiredSize <= 0) {
// A manual backpressure check.
if (this.pendingPulls.length !== 0) {
// A case of waiting pull finished (= not yet canceled)
const pending = this.pendingPulls.shift();
pending.resolve();
}
return;
}
readNext();
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,29 @@ assert.throws(() => new Blob({}), {
reader.closed.then(common.mustCall());
})().then(common.mustCall());

(async () => {
const b = new Blob(['A', 'B', 'C']);
const stream = b.stream();
const chunks = [];
const decoder = new TextDecoder();
await stream.pipeTo(new WritableStream({
write(chunk) {
chunks.push(decoder.decode(chunk, { stream: true }));
}
}));
assert.strictEqual(chunks.join(''), 'ABC');
})().then(common.mustCall());

(async () => {
const file = new Blob(['<svg></svg>'], { type: 'image/svg+xml' });
const url = URL.createObjectURL(file);
const res = await fetch(url);
const blob = await res.blob();
assert.strictEqual(blob.size, 11);
assert.strictEqual(blob.type, 'image/svg+xml');
assert.strictEqual(await blob.text(), '<svg></svg>');
})().then(common.mustCall());

(async () => {
const b = new Blob(Array(10).fill('hello'));
const stream = b.stream();
Expand Down

0 comments on commit a3af3cb

Please sign in to comment.