Created
February 14, 2017 19:56
-
-
Save TheNoim/573a1b41bbd85853e43dfc576a5fae58 to your computer and use it in GitHub Desktop.
Encode DSB mobile payload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by nilsbergmann on 14.02.17. | |
*/ | |
const pako = require('pako'); | |
const a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
function btoa(b) { | |
let c, d, e = ""; | |
for (c = 0, | |
d = b.length; d > c; c += 3) { | |
const f = 255 & b.charCodeAt(c) | |
, g = 255 & b.charCodeAt(c + 1) | |
, h = 255 & b.charCodeAt(c + 2) | |
, i = f >> 2 | |
, j = (3 & f) << 4 | g >> 4 | |
, k = d > c + 1 ? (15 & g) << 2 | h >> 6 : 64 | |
, l = d > c + 2 ? 63 & h : 64; | |
e += a.charAt(i) + a.charAt(j) + a.charAt(k) + a.charAt(l) | |
} | |
return e | |
} | |
module.exports = function (ObjectToEncode) { | |
let b = pako.deflate(JSON.stringify(ObjectToEncode), { | |
to: "string", | |
gzip: !0 | |
}); | |
return b = btoa(b); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment