Skip to content

Commit 85705a4

Browse files
authored
buffer: fix blob range error with many chunks
PR-URL: #47320 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent 1168ab6 commit 85705a4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internal/blob.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const {
6969
CountQueuingStrategy,
7070
} = require('internal/webstreams/queuingstrategies');
7171

72+
const { queueMicrotask } = require('internal/process/task_queues');
73+
7274
const kHandle = Symbol('kHandle');
7375
const kType = Symbol('kType');
7476
const kLength = Symbol('kLength');
@@ -284,7 +286,7 @@ class Blob {
284286
}
285287
if (buffer !== undefined)
286288
buffers.push(buffer);
287-
readNext();
289+
queueMicrotask(() => readNext());
288290
});
289291
};
290292
readNext();

test/parallel/test-blob.js

+13
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,16 @@ assert.throws(() => new Blob({}), {
315315

316316
delete Object.prototype.type;
317317
}
318+
319+
(async () => {
320+
// Refs: https://github.com/nodejs/node/issues/47301
321+
322+
const random = Buffer.alloc(256).fill('0');
323+
const chunks = [];
324+
325+
for (let i = 0; i < random.length; i += 2) {
326+
chunks.push(random.subarray(i, i + 2));
327+
}
328+
329+
await new Blob(chunks).arrayBuffer();
330+
})().then(common.mustCall());

0 commit comments

Comments
 (0)