Skip to content

Commit

Permalink
lib/internal/blob.js: 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 5a661b9
Show file tree
Hide file tree
Showing 2 changed files with 18 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
13 changes: 13 additions & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ 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 b = new Blob(Array(10).fill('hello'));
const stream = b.stream();
Expand Down

0 comments on commit 5a661b9

Please sign in to comment.