Skip to content

Commit 28761de

Browse files
Gozaladanielleadams
authored andcommitted
buffer: fix Blob constructor on various TypedArrays
Fixes: #40705 PR-URL: #40706 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d3de937 commit 28761de

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/internal/blob.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ function getSource(source, endings) {
114114

115115
// We copy into a new Uint8Array because the underlying
116116
// BackingStores are going to be detached and owned by
117-
// the Blob. We also don't want to have to worry about
118-
// byte offsets.
119-
source = new Uint8Array(source);
120-
return [source.byteLength, source];
117+
// the Blob.
118+
const { buffer, byteOffset, byteLength } = source;
119+
const slice = buffer.slice(byteOffset, byteOffset + byteLength);
120+
return [byteLength, new Uint8Array(slice)];
121121
}
122122

123123
class Blob {

test/parallel/test-blob.js

+15
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,18 @@ assert.throws(() => new Blob({}), {
229229
});
230230
});
231231
}
232+
233+
(async () => {
234+
const blob = new Blob([
235+
new Uint8Array([0x50, 0x41, 0x53, 0x53]),
236+
new Int8Array([0x50, 0x41, 0x53, 0x53]),
237+
new Uint16Array([0x4150, 0x5353]),
238+
new Int16Array([0x4150, 0x5353]),
239+
new Uint32Array([0x53534150]),
240+
new Int32Array([0x53534150]),
241+
new Float32Array([0xD341500000]),
242+
]);
243+
244+
assert.strictEqual(blob.size, 28);
245+
assert.strictEqual(blob.type, '');
246+
})().then(common.mustCall());

0 commit comments

Comments
 (0)