-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.ts
More file actions
executable file
·48 lines (26 loc) · 785 Bytes
/
browser.ts
File metadata and controls
executable file
·48 lines (26 loc) · 785 Bytes
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
/* MAIN */
const Browser = {
/* API */
encode: ( data: Uint8Array ): string => {
let string = '';
for ( let i = 0, l = data.length - 1; i < l; i += 2 ) { // Skipping a potential trailing odd byte
const charCode = data[i] + ( data[i + 1] * 256 );
const char = String.fromCharCode ( charCode );
string += char;
}
return string;
},
decode: ( data: string ): Uint8Array => {
const uint8 = new Uint8Array ( data.length * 2 );
for ( let i = 0, l = data.length; i < l; i++ ) {
const charCode = data.charCodeAt ( i );
const hi = ( charCode >> 8 );
const lo = ( charCode % 256 );
uint8[i * 2] = lo;
uint8[(i * 2) + 1] = hi;
}
return uint8;
}
};
/* EXPORT */
export default Browser;