Skip to content

More efficient Uint8Array conversion #2645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/firestore/src/api/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ export class Blob {
if (!(array instanceof Uint8Array)) {
throw invalidClassError('Blob.fromUint8Array', 'Uint8Array', 1, array);
}
// We can't call array.map directly because it expects the return type to
// be a Uint8Array, whereas we can convert it to a regular array by invoking
// map on the Array prototype.
const binaryString = Array.prototype.map
.call(array, (char: number) => {
return String.fromCharCode(char);
})
.join('');
let binaryString = '';
for (let i = 0; i < array.length; ++i) {
binaryString += String.fromCharCode(array[i]);
}
return new Blob(binaryString);
}

Expand Down