Skip to content

Commit

Permalink
fix lib/internal/blob.js for nodejs#48668 nodejs#48916
Browse files Browse the repository at this point in the history
- also work example code in nodejs#48232
  • Loading branch information
bellbind committed Jul 26, 2023
1 parent 1eae568 commit e8dcf79
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) {
// 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 e8dcf79

Please sign in to comment.