Commit 5a8195ec90ba51f0c5d8272e9cd56428f32f0f61
hack to make base64 decoding work on electron
Dominic Tarr committed on 5/16/2016, 12:55:16 AMParent: acf540c2691b08760271ba3972a2e680551a55dc
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -58,14 +58,28 @@ | ||
58 | 58 | } |
59 | 59 | |
60 | 60 | function empty(v) { return !!v } |
61 | 61 | |
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 | + | |
62 | 76 | function toBuffer(buf) { |
63 | 77 | if(buf == null) return buf |
64 | 78 | if(Buffer.isBuffer(buf)) throw new Error('already a buffer') |
65 | 79 | var i = buf.indexOf('.') |
66 | 80 | 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)) | |
68 | 82 | } |
69 | 83 | |
70 | 84 | function toUint8(buf) { |
71 | 85 | return new Uint8Array(toBuffer(buf)) |
Built with git-ssb-web