-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
52 lines (43 loc) · 1.27 KB
/
util.js
File metadata and controls
52 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function deflate(arr) {
return pako.deflateRaw(arr, {
"level": 9
});
}
function inflate(arr) {
return pako.inflateRaw(arr);
}
function encode(str) {
var bytes = new TextEncoder("utf-8").encode(str);
return deflate(bytes);
}
function arrToB64(arr) {
var bytestr = "";
arr.forEach(c => bytestr += String.fromCharCode(c));
return btoa(bytestr).replace(/\+/g, "@").replace(/=+/, "");
}
function b64ToArr(str) {
return new Uint8Array([...atob(decodeURIComponent(str).replace(/@/g, "+"))].map(c => c.charCodeAt()))
}
function byteStringToByteArray(byteString) {
var byteArray = new Uint8Array(byteString.length);
for(var i = 0; i < byteString.length; i++)
byteArray[i] = byteString.charCodeAt(i);
byteArray.head = 0;
return byteArray;
}
function textToByteString(string) {
return window.unescape(window.encodeURIComponent(string));
}
function byteStringToText(string){
return window.decodeURIComponent(window.escape(string));
}
function byteArrayToByteString(byteArray) {
var retval = "";
byteArray.forEach(function(byte) {
retval += String.fromCharCode(byte);
});
return retval;
}
function byteStringToBase64(byteString) {
return window.btoa(byteString).replace(/\+/g, "@").replace(/=+/, "");
}