Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ dist
dev
.nyc_output
test-results.json
.idea/
30 changes: 16 additions & 14 deletions src/6_branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1340,20 +1340,22 @@ Branch.prototype['qrCode'] = wrap(
this._api(
resources.qrCode,
utils.cleanLinkData(linkData),
function(error, rawBuffer) {
function QrCode() { }

if (!error) {
QrCode['rawBuffer'] = rawBuffer;
QrCode['base64'] = function() {
// First Encode array buffer as UTF-8 String, then Base64 Encode
if (this['rawBuffer']) {
return btoa(String.fromCharCode.apply(null, new Uint8Array(this['rawBuffer'])));
}
throw Error('QrCode.rawBuffer is empty.');
};
}
return done(error || null, QrCode || null);
(error, rawBuffer) => {
if (error) return done(error, null);

const QrCode = {
rawBuffer,
base64() {
if (!this.rawBuffer) throw new Error('QrCode.rawBuffer is empty.');
// Encode the Uint8Array to a binary string, then convert to base64
const binaryString = Array.from(new Uint8Array(this.rawBuffer))
.map(byte => String.fromCharCode(byte))
.join('');
return btoa(binaryString);
}
};

return done(null, QrCode);
}
);
}
Expand Down
Loading