Skip to content

Instantly share code, notes, and snippets.

@TheNoim
Created February 14, 2017 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheNoim/6cdd422ddf2ff30b54de9fe0397bb153 to your computer and use it in GitHub Desktop.
Save TheNoim/6cdd422ddf2ff30b54de9fe0397bb153 to your computer and use it in GitHub Desktop.
DSB encoding
var pako = require('pako');
var a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function btoa(b) {
var c, d, e = "";
for (c = 0,
d = b.length; d > c; c += 3) {
var 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
}
function b(a) {
var b = pako.deflate(JSON.stringify(a), {
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