From e8dcf7987199e79f10ad117a529e8583f3b9fbfa Mon Sep 17 00:00:00 2001 From: bellbind Date: Wed, 26 Jul 2023 22:24:02 +0900 Subject: [PATCH 1/2] fix lib/internal/blob.js for #48668 #48916 - also work example code in #48232 --- lib/internal/blob.js | 5 +++++ test/parallel/test-blob.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 655023e07780f2..176b4c88c0aa73 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -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(); diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index 27dee5690d7e06..c6c1814d5cd2c5 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -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(); From b7d9941036baa7abd34488405f3f24cfe0c37e25 Mon Sep 17 00:00:00 2001 From: bellbind Date: Thu, 27 Jul 2023 08:14:42 +0900 Subject: [PATCH 2/2] lib: fix lib/internal/blob.js Blob.stream() for #48668 #48916 Add lacked calling resolve() for finish ReadableStream source.pull(). Fixes: #48668 Fixes: #48916 Fixes: #48232 Refs: 8cc1438 --- lib/internal/blob.js | 2 +- test/parallel/test-blob.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 176b4c88c0aa73..c5b417ddc291b6 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -361,7 +361,7 @@ class Blob { if (c.desiredSize <= 0) { // A manual backpressure check. if (this.pendingPulls.length !== 0) { - // case of waiting pull finished (= not yet canceled) + // A case of waiting pull finished (= not yet canceled) const pending = this.pendingPulls.shift(); pending.resolve(); } diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index c6c1814d5cd2c5..e0c28389511639 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -270,16 +270,16 @@ assert.throws(() => new Blob({}), { })().then(common.mustCall()); (async () => { - const b = new Blob(["A", "B", "C"]); + 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})); + chunks.push(decoder.decode(chunk, { stream: true })); } })); - assert.strictEqual(chunks.join(""), "ABC"); + assert.strictEqual(chunks.join(''), 'ABC'); })().then(common.mustCall()); (async () => {