Skip to content

Commit e3ea37a

Browse files
committed
[patch] use binary encoding function that does not overflow
If the qr codes get too big (in total file size), then the current function will blow up. This one works better, tested manually by updating the dist/build.js, and updating example.html to point to that instead of the production cdn hosted websdk
1 parent 152106f commit e3ea37a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/6_branch.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,19 +1340,22 @@ Branch.prototype['qrCode'] = wrap(
13401340
this._api(
13411341
resources.qrCode,
13421342
utils.cleanLinkData(linkData),
1343-
function(error, rawBuffer) {
1344-
function QrCode() { }
1345-
if (!error) {
1346-
QrCode['rawBuffer'] = rawBuffer;
1347-
QrCode['base64'] = function() {
1348-
// First Encode array buffer as UTF-8 String, then Base64 Encode
1349-
if (this['rawBuffer']) {
1350-
return btoa(String.fromCharCode.apply(null, new Uint8Array(this['rawBuffer'])));
1351-
}
1352-
throw Error('QrCode.rawBuffer is empty.');
1353-
};
1354-
}
1355-
return done(error || null, QrCode || null);
1343+
(error, rawBuffer) => {
1344+
if (error) return done(error, null);
1345+
1346+
const QrCode = {
1347+
rawBuffer,
1348+
base64() {
1349+
if (!this.rawBuffer) throw new Error('QrCode.rawBuffer is empty.');
1350+
// Encode the Uint8Array to a binary string, then convert to base64
1351+
const binaryString = Array.from(new Uint8Array(this.rawBuffer))
1352+
.map(byte => String.fromCharCode(byte))
1353+
.join('');
1354+
return btoa(binaryString);
1355+
}
1356+
};
1357+
1358+
return done(null, QrCode);
13561359
}
13571360
);
13581361
}

0 commit comments

Comments
 (0)