Skip to content

Commit d2b37c1

Browse files
author
Brian Chen
authored
more efficient Uint8Array conversion (#2645)
1 parent 20ab129 commit d2b37c1

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

packages/firestore/src/api/blob.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,10 @@ export class Blob {
8585
if (!(array instanceof Uint8Array)) {
8686
throw invalidClassError('Blob.fromUint8Array', 'Uint8Array', 1, array);
8787
}
88-
// We can't call array.map directly because it expects the return type to
89-
// be a Uint8Array, whereas we can convert it to a regular array by invoking
90-
// map on the Array prototype.
91-
const binaryString = Array.prototype.map
92-
.call(array, (char: number) => {
93-
return String.fromCharCode(char);
94-
})
95-
.join('');
88+
let binaryString = '';
89+
for (let i = 0; i < array.length; ++i) {
90+
binaryString += String.fromCharCode(array[i]);
91+
}
9692
return new Blob(binaryString);
9793
}
9894

0 commit comments

Comments
 (0)