Skip to content

Commit ccc8d89

Browse files
authored
[patch] use binary encoding function that does not overflow for qr (#1075)
# Pull Request Template ## Description 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 I couldnt get this new one to overflow Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Unit test - [ ] Integration test ## JS Budget Check Please mention the size in kb before abd after this PR | Files | Before | After | | ----------- | ----------- | ----------- | | dist/build.js. | | | | dist/build.min.js| | | ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules - [ ] I have checked my code and corrected any misspellings ## Mentions: List the person or team responsible for reviewing proposed changes. cc @BranchMetrics/saas-sdk-devs for visibility.
1 parent e2b3837 commit ccc8d89

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ dist
3535
dev
3636
.nyc_output
3737
test-results.json
38+
.idea/

src/6_branch.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,20 +1340,22 @@ Branch.prototype['qrCode'] = wrap(
13401340
this._api(
13411341
resources.qrCode,
13421342
utils.cleanLinkData(linkData),
1343-
function(error, rawBuffer) {
1344-
function QrCode() { }
1345-
1346-
if (!error) {
1347-
QrCode['rawBuffer'] = rawBuffer;
1348-
QrCode['base64'] = function() {
1349-
// First Encode array buffer as UTF-8 String, then Base64 Encode
1350-
if (this['rawBuffer']) {
1351-
return btoa(String.fromCharCode.apply(null, new Uint8Array(this['rawBuffer'])));
1352-
}
1353-
throw Error('QrCode.rawBuffer is empty.');
1354-
};
1355-
}
1356-
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);
13571359
}
13581360
);
13591361
}

0 commit comments

Comments
 (0)