parent
db5683a69d
commit
7b23e24b71
5 changed files with 92 additions and 70 deletions
|
@ -24,6 +24,7 @@
|
|||
<script type="text/javascript" src="js/websocket.js"></script>
|
||||
<script type="text/javascript" src="js/websocket-resources.js"></script>
|
||||
<script type="text/javascript" src="js/helpers.js"></script>
|
||||
<script type="text/javascript" src="js/stringview.js"></script>
|
||||
<script type="text/javascript" src="js/storage.js"></script>
|
||||
<script type="text/javascript" src="js/storage/devices.js"></script>
|
||||
<script type="text/javascript" src="js/storage/groups.js"></script>
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
<script type="text/javascript" src="js/websocket.js"></script>
|
||||
<script type="text/javascript" src="js/websocket-resources.js"></script>
|
||||
<script type="text/javascript" src="js/helpers.js"></script>
|
||||
<script type="text/javascript" src="js/stringview.js"></script>
|
||||
<script type="text/javascript" src="js/storage.js"></script>
|
||||
<script type="text/javascript" src="js/storage/devices.js"></script>
|
||||
<script type="text/javascript" src="js/storage/groups.js"></script>
|
||||
|
|
156
js/stringview.js
156
js/stringview.js
|
@ -1,79 +1,97 @@
|
|||
"use strict";
|
||||
|
||||
/*
|
||||
* These functions are from the Mozilla Developer Network
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
|
||||
/* vim: ts=4:sw=4:expandtab
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
;(function() {
|
||||
"use strict";
|
||||
|
||||
var StringView = {
|
||||
window.StringView = {
|
||||
|
||||
b64ToUint6: function(nChr) {
|
||||
return nChr > 64 && nChr < 91 ?
|
||||
nChr - 65
|
||||
: nChr > 96 && nChr < 123 ?
|
||||
nChr - 71
|
||||
: nChr > 47 && nChr < 58 ?
|
||||
nChr + 4
|
||||
: nChr === 43 ?
|
||||
62
|
||||
: nChr === 47 ?
|
||||
63
|
||||
:
|
||||
0;
|
||||
},
|
||||
/*
|
||||
* These functions from the Mozilla Developer Network
|
||||
* and have been placed in the public domain.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
|
||||
* https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses
|
||||
*/
|
||||
|
||||
base64ToBytes: function(sBase64, nBlocksSize) {
|
||||
var
|
||||
sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""), nInLen = sB64Enc.length,
|
||||
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2;
|
||||
var aBBytes = new ArrayBuffer(nOutLen);
|
||||
var taBytes = new Uint8Array(aBBytes);
|
||||
b64ToUint6: function(nChr) {
|
||||
return nChr > 64 && nChr < 91 ?
|
||||
nChr - 65
|
||||
: nChr > 96 && nChr < 123 ?
|
||||
nChr - 71
|
||||
: nChr > 47 && nChr < 58 ?
|
||||
nChr + 4
|
||||
: nChr === 43 ?
|
||||
62
|
||||
: nChr === 47 ?
|
||||
63
|
||||
:
|
||||
0;
|
||||
},
|
||||
|
||||
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
|
||||
nMod4 = nInIdx & 3;
|
||||
nUint24 |= StringView.b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
|
||||
if (nMod4 === 3 || nInLen - nInIdx === 1) {
|
||||
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
|
||||
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
||||
base64ToBytes: function(sBase64, nBlocksSize) {
|
||||
var
|
||||
sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""), nInLen = sB64Enc.length,
|
||||
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2;
|
||||
var aBBytes = new ArrayBuffer(nOutLen);
|
||||
var taBytes = new Uint8Array(aBBytes);
|
||||
|
||||
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
|
||||
nMod4 = nInIdx & 3;
|
||||
nUint24 |= StringView.b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
|
||||
if (nMod4 === 3 || nInLen - nInIdx === 1) {
|
||||
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
|
||||
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
||||
}
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
return aBBytes;
|
||||
},
|
||||
return aBBytes;
|
||||
},
|
||||
|
||||
uint6ToB64: function(nUint6) {
|
||||
return nUint6 < 26 ?
|
||||
nUint6 + 65
|
||||
: nUint6 < 52 ?
|
||||
nUint6 + 71
|
||||
: nUint6 < 62 ?
|
||||
nUint6 - 4
|
||||
: nUint6 === 62 ?
|
||||
43
|
||||
: nUint6 === 63 ?
|
||||
47
|
||||
:
|
||||
65;
|
||||
},
|
||||
uint6ToB64: function(nUint6) {
|
||||
return nUint6 < 26 ?
|
||||
nUint6 + 65
|
||||
: nUint6 < 52 ?
|
||||
nUint6 + 71
|
||||
: nUint6 < 62 ?
|
||||
nUint6 - 4
|
||||
: nUint6 === 62 ?
|
||||
43
|
||||
: nUint6 === 63 ?
|
||||
47
|
||||
:
|
||||
65;
|
||||
},
|
||||
|
||||
bytesToBase64: function(aBytes) {
|
||||
var nMod3, sB64Enc = "";
|
||||
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
|
||||
nMod3 = nIdx % 3;
|
||||
if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += "\r\n"; }
|
||||
nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
|
||||
if (nMod3 === 2 || aBytes.length - nIdx === 1) {
|
||||
sB64Enc += String.fromCharCode(
|
||||
StringView.uint6ToB64(nUint24 >>> 18 & 63),
|
||||
StringView.uint6ToB64(nUint24 >>> 12 & 63),
|
||||
StringView.uint6ToB64(nUint24 >>> 6 & 63),
|
||||
StringView.uint6ToB64(nUint24 & 63)
|
||||
);
|
||||
nUint24 = 0;
|
||||
bytesToBase64: function(aBytes) {
|
||||
var nMod3, sB64Enc = "";
|
||||
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
|
||||
nMod3 = nIdx % 3;
|
||||
if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += "\r\n"; }
|
||||
nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
|
||||
if (nMod3 === 2 || aBytes.length - nIdx === 1) {
|
||||
sB64Enc += String.fromCharCode(
|
||||
StringView.uint6ToB64(nUint24 >>> 18 & 63),
|
||||
StringView.uint6ToB64(nUint24 >>> 12 & 63),
|
||||
StringView.uint6ToB64(nUint24 >>> 6 & 63),
|
||||
StringView.uint6ToB64(nUint24 & 63)
|
||||
);
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
return sB64Enc.replace(/A(?=A$|$)/g, "=");
|
||||
}
|
||||
}
|
||||
return sB64Enc.replace(/A(?=A$|$)/g, "=");
|
||||
}
|
||||
};
|
||||
};
|
||||
}());
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
<script type="text/javascript" src="js/websocket.js"></script>
|
||||
<script type="text/javascript" src="js/websocket-resources.js"></script>
|
||||
<script type="text/javascript" src="js/helpers.js"></script>
|
||||
<script type="text/javascript" src="js/stringview.js"></script>
|
||||
<script type="text/javascript" src="js/storage.js"></script>
|
||||
<script type="text/javascript" src="js/storage/devices.js"></script>
|
||||
<script type="text/javascript" src="js/storage/groups.js"></script>
|
||||
|
|
|
@ -128,7 +128,8 @@
|
|||
<script type="text/javascript" src="../js/protobufs.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/websocket.js"></script>
|
||||
<script type="text/javascript" src="../js/websocket-resources.js"></script>
|
||||
<script type="text/javascript" src="../js/helpers.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/helpers.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/stringview.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/storage.js"></script>
|
||||
<script type="text/javascript" src="../js/storage/devices.js"></script>
|
||||
<script type="text/javascript" src="../js/storage/groups.js"></script>
|
||||
|
|
Loading…
Reference in a new issue