git ssb

1+

Dominic / ssb-keys



Commit 5a8195ec90ba51f0c5d8272e9cd56428f32f0f61

hack to make base64 decoding work on electron

Dominic Tarr committed on 5/16/2016, 12:55:16 AM
Parent: acf540c2691b08760271ba3972a2e680551a55dc

Files changed

index.jschanged
index.jsView
@@ -58,14 +58,28 @@
5858 }
5959
6060 function empty(v) { return !!v }
6161
62+//crazy hack to make electron not crash
63+function base64ToBuffer(s) {
64+ var l = s.length * 6 / 8
65+ if(s[s.length - 2] == '=')
66+ l = l - 2
67+ else
68+ if(s[s.length - 1] == '=')
69+ l = l - 1
70+
71+ var b = new Buffer(l)
72+ b.write(s, 'base64')
73+ return b
74+}
75+
6276 function toBuffer(buf) {
6377 if(buf == null) return buf
6478 if(Buffer.isBuffer(buf)) throw new Error('already a buffer')
6579 var i = buf.indexOf('.')
6680 var start = (hasSigil(buf)) ? 1 : 0
67- return new Buffer(buf.substring(start, ~i ? i : buf.length), 'base64')
81+ return base64ToBuffer(buf.substring(start, ~i ? i : buf.length))
6882 }
6983
7084 function toUint8(buf) {
7185 return new Uint8Array(toBuffer(buf))

Built with git-ssb-web