Skip to content

Commit

Permalink
Merge pull request #123 from grimmdude/fix_browser_base64_bug
Browse files Browse the repository at this point in the history
Fix browser base64 bug
  • Loading branch information
grimmdude authored Sep 27, 2023
2 parents 533ade7 + d127866 commit 93bfbb4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ class Writer {
*/
base64(): string {
if (typeof btoa === 'function') {
return btoa(String.fromCharCode.apply(null, this.buildFile()));
let binary = '';
const bytes = this.buildFile();
const len = bytes.byteLength;

for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}

return btoa(binary);
}

return Buffer.from(this.buildFile()).toString('base64');
Expand Down

0 comments on commit 93bfbb4

Please sign in to comment.