base128-ascii 2.1.10 → 2.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/browser.min.js +1 -1
- package/package.json +14 -12
- package/src/main.d.ts +12 -0
- package/src/main.js +86 -0
- package/{dist/index.d.ts → src/module.d.mts} +2 -2
- package/src/module.mjs +88 -0
- package/dist/browser.js +0 -57
- package/dist/index.js +0 -58
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ const decoded = base128.decode(eval(encodedTemplate))
|
|
|
23
23
|
|
|
24
24
|
```html browser
|
|
25
25
|
<script>
|
|
26
|
-
{class EncodeOutput{constructor(t){this.uint8Array=t}toString(){return(new TextDecoder).decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,t=>"\r"==t?"\\r":"<\/script"==t?"<\\/script":"\\"+t)}\``}}
|
|
26
|
+
{class EncodeOutput{constructor(t){this.uint8Array=t}toString(){return(new TextDecoder).decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,t=>"\r"==t?"\\r":"<\/script"==t?"<\\/script":"\\"+t)}\``}}this.base128={EncodeOutput,encode(t){"string"==typeof t&&(t=(new TextEncoder).encode(t));for(var e=t.length,r=new Uint8Array(Math.ceil(e/7*8)),n=0,c=0;n<e;)r[c++]=t[n]>>1&127,r[c++]=127&(t[n++]<<6|t[n]>>2),r[c++]=127&(t[n++]<<5|t[n]>>3),r[c++]=127&(t[n++]<<4|t[n]>>4),r[c++]=127&(t[n++]<<3|t[n]>>5),r[c++]=127&(t[n++]<<2|t[n]>>6),r[c++]=127&(t[n++]<<1|t[n]>>7),r[c++]=127&t[n++];return new EncodeOutput(r)},decode(t){for(var e,r=t.length,n=new Uint8Array(r/8*7),c=0,o=0,i=()=>(e=t.charCodeAt(c++))>127?e=0:e;c<r;)n[o++]=i()<<1|i()>>6,n[o++]=e<<2|i()>>5,n[o++]=e<<3|i()>>4,n[o++]=e<<4|i()>>3,n[o++]=e<<5|i()>>2,n[o++]=e<<6|i()>>1,n[o++]=e<<7|i();return n}}}
|
|
27
27
|
</script>
|
|
28
28
|
```
|
|
29
29
|
|
package/dist/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{class EncodeOutput{constructor(t){this.uint8Array=t}toString(){return(new TextDecoder).decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,t=>"\r"==t?"\\r":"<\/script"==t?"<\\/script":"\\"+t)}\``}}
|
|
1
|
+
{class EncodeOutput{constructor(t){this.uint8Array=t}toString(){return(new TextDecoder).decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,t=>"\r"==t?"\\r":"<\/script"==t?"<\\/script":"\\"+t)}\``}}this.base128={EncodeOutput,encode(t){"string"==typeof t&&(t=(new TextEncoder).encode(t));for(var e=t.length,r=new Uint8Array(Math.ceil(e/7*8)),n=0,c=0;n<e;)r[c++]=t[n]>>1&127,r[c++]=127&(t[n++]<<6|t[n]>>2),r[c++]=127&(t[n++]<<5|t[n]>>3),r[c++]=127&(t[n++]<<4|t[n]>>4),r[c++]=127&(t[n++]<<3|t[n]>>5),r[c++]=127&(t[n++]<<2|t[n]>>6),r[c++]=127&(t[n++]<<1|t[n]>>7),r[c++]=127&t[n++];return new EncodeOutput(r)},decode(t){for(var e,r=t.length,n=new Uint8Array(r/8*7),c=0,o=0,i=()=>(e=t.charCodeAt(c++))>127?e=0:e;c<r;)n[o++]=i()<<1|i()>>6,n[o++]=e<<2|i()>>5,n[o++]=e<<3|i()>>4,n[o++]=e<<4|i()>>3,n[o++]=e<<5|i()>>2,n[o++]=e<<6|i()>>1,n[o++]=e<<7|i();return n}}}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "base128-ascii",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "2.1.12",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/main.js",
|
|
6
|
+
"module": "./src/module.mjs",
|
|
7
|
+
"browser": "./dist/browser.min.js",
|
|
7
8
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"test": "
|
|
10
|
-
"prepublishOnly": "
|
|
9
|
+
"build": "es-check es6 --checkFeatures --module src/**/*.mjs && rimraf dist && node scripts/minify.mjs && es-check es6 --checkFeatures dist/**/*.js src/**/*.js",
|
|
10
|
+
"test": "node --run build && node scripts/test.mjs",
|
|
11
|
+
"prepublishOnly": "node --run test"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -16,20 +17,21 @@
|
|
|
16
17
|
"author": "bddjr",
|
|
17
18
|
"license": "Unlicense",
|
|
18
19
|
"files": [
|
|
19
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
20
22
|
],
|
|
21
23
|
"keywords": [
|
|
22
24
|
"base128",
|
|
23
25
|
"base64",
|
|
24
26
|
"ascii",
|
|
25
27
|
"encode",
|
|
26
|
-
"decode"
|
|
28
|
+
"decode",
|
|
29
|
+
"atob",
|
|
30
|
+
"btoa"
|
|
27
31
|
],
|
|
28
32
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^24.0.3",
|
|
30
33
|
"es-check": "^9.5.3",
|
|
31
34
|
"rimraf": "^6.0.1",
|
|
32
|
-
"terser": "^5.44.1"
|
|
33
|
-
"typescript": "^5.7.3"
|
|
35
|
+
"terser": "^5.44.1"
|
|
34
36
|
}
|
|
35
37
|
}
|
package/src/main.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class EncodeOutput {
|
|
2
|
+
constructor(out: Uint8Array);
|
|
3
|
+
uint8Array: Uint8Array;
|
|
4
|
+
toString(): string;
|
|
5
|
+
toJSTemplateLiterals(): string;
|
|
6
|
+
}
|
|
7
|
+
declare const base128: {
|
|
8
|
+
EncodeOutput: typeof EncodeOutput;
|
|
9
|
+
encode(input: Uint8Array | string): EncodeOutput;
|
|
10
|
+
decode(input: string): Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
export = base128;
|
package/src/main.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
|
|
3
|
+
class EncodeOutput {
|
|
4
|
+
/**
|
|
5
|
+
* @param {Uint8Array} out
|
|
6
|
+
*/
|
|
7
|
+
constructor(out) {
|
|
8
|
+
this.uint8Array = out
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return new TextDecoder().decode(this.uint8Array)
|
|
12
|
+
}
|
|
13
|
+
toJSTemplateLiterals() {
|
|
14
|
+
return `\`${this.toString().replace(
|
|
15
|
+
/[\r\\`]|\${|<\/script/g,
|
|
16
|
+
(match) => (
|
|
17
|
+
match == '\r'
|
|
18
|
+
? '\\r'
|
|
19
|
+
: match == '</script'
|
|
20
|
+
? '<\\/script'
|
|
21
|
+
: '\\' + match
|
|
22
|
+
)
|
|
23
|
+
)}\``
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
EncodeOutput,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {Uint8Array | string} input
|
|
32
|
+
*/
|
|
33
|
+
encode(input) {
|
|
34
|
+
if (typeof input == 'string')
|
|
35
|
+
input = new TextEncoder().encode(input)
|
|
36
|
+
var il = input.length
|
|
37
|
+
, out = new Uint8Array(Math.ceil(il / 7 * 8))
|
|
38
|
+
, ii = 0
|
|
39
|
+
, oi = 0
|
|
40
|
+
while (ii < il) {
|
|
41
|
+
// 0 1 2 3 4 5 6 7
|
|
42
|
+
// in 00000000 11111111 22222222 33333333 44444444 55555555 66666666
|
|
43
|
+
// out _0000000 _0111111 _1122222 _2223333 _3333444 _4444455 _5555556 _6666666
|
|
44
|
+
|
|
45
|
+
/* 0 */ out[oi++] = input[ii] >> 1 & 127
|
|
46
|
+
/* 1 */ out[oi++] = (input[ii++] << 6 | input[ii] >> 2) & 127
|
|
47
|
+
/* 2 */ out[oi++] = (input[ii++] << 5 | input[ii] >> 3) & 127
|
|
48
|
+
/* 3 */ out[oi++] = (input[ii++] << 4 | input[ii] >> 4) & 127
|
|
49
|
+
/* 4 */ out[oi++] = (input[ii++] << 3 | input[ii] >> 5) & 127
|
|
50
|
+
/* 5 */ out[oi++] = (input[ii++] << 2 | input[ii] >> 6) & 127
|
|
51
|
+
/* 6 */ out[oi++] = (input[ii++] << 1 | input[ii] >> 7) & 127
|
|
52
|
+
/* 7 */ out[oi++] = input[ii++] & 127
|
|
53
|
+
}
|
|
54
|
+
return new EncodeOutput(out)
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} input
|
|
59
|
+
*/
|
|
60
|
+
decode(input) {
|
|
61
|
+
var il = input.length
|
|
62
|
+
, out = new Uint8Array(il / 8 * 7)
|
|
63
|
+
, ii = 0
|
|
64
|
+
, oi = 0
|
|
65
|
+
, cache
|
|
66
|
+
, next = () => (
|
|
67
|
+
(cache = input.charCodeAt(ii++)) > 127
|
|
68
|
+
? cache = 0 // In HTML, 0 is likely to be converted to 65533 (�)
|
|
69
|
+
: cache
|
|
70
|
+
)
|
|
71
|
+
while (ii < il) {
|
|
72
|
+
// 0 1 2 3 4 5 6 7
|
|
73
|
+
// in _0000000 _1111111 _2222222 _3333333 _4444444 _5555555 _6666666 _7777777
|
|
74
|
+
// out 00000001 11111122 22222333 33334444 44455555 55666666 67777777
|
|
75
|
+
|
|
76
|
+
/* 0 */ out[oi++] = next() << 1 | next() >> 6
|
|
77
|
+
/* 1 */ out[oi++] = cache << 2 | next() >> 5
|
|
78
|
+
/* 2 */ out[oi++] = cache << 3 | next() >> 4
|
|
79
|
+
/* 3 */ out[oi++] = cache << 4 | next() >> 3
|
|
80
|
+
/* 4 */ out[oi++] = cache << 5 | next() >> 2
|
|
81
|
+
/* 5 */ out[oi++] = cache << 6 | next() >> 1
|
|
82
|
+
/* 6 */ out[oi++] = cache << 7 | next()
|
|
83
|
+
}
|
|
84
|
+
return out
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type Uint8ArrayLike = ArrayLike<number>;
|
|
2
1
|
export declare class EncodeOutput {
|
|
3
2
|
constructor(out: Uint8Array);
|
|
3
|
+
uint8Array: Uint8Array;
|
|
4
4
|
toString(): string;
|
|
5
5
|
toJSTemplateLiterals(): string;
|
|
6
6
|
}
|
|
7
|
-
export declare function encode(input:
|
|
7
|
+
export declare function encode(input: Uint8Array | string): EncodeOutput;
|
|
8
8
|
export declare function decode(input: string): Uint8Array;
|
|
9
9
|
declare const base128: {
|
|
10
10
|
EncodeOutput: typeof EncodeOutput;
|
package/src/module.mjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
|
|
3
|
+
export class EncodeOutput {
|
|
4
|
+
/**
|
|
5
|
+
* @param {Uint8Array} out
|
|
6
|
+
*/
|
|
7
|
+
constructor(out) {
|
|
8
|
+
this.uint8Array = out
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return new TextDecoder().decode(this.uint8Array)
|
|
12
|
+
}
|
|
13
|
+
toJSTemplateLiterals() {
|
|
14
|
+
return `\`${this.toString().replace(
|
|
15
|
+
/[\r\\`]|\${|<\/script/g,
|
|
16
|
+
(match) => (
|
|
17
|
+
match == '\r'
|
|
18
|
+
? '\\r'
|
|
19
|
+
: match == '</script'
|
|
20
|
+
? '<\\/script'
|
|
21
|
+
: '\\' + match
|
|
22
|
+
)
|
|
23
|
+
)}\``
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Uint8Array | string} input
|
|
29
|
+
*/
|
|
30
|
+
export function encode(input) {
|
|
31
|
+
if (typeof input == 'string')
|
|
32
|
+
input = new TextEncoder().encode(input)
|
|
33
|
+
var il = input.length
|
|
34
|
+
, out = new Uint8Array(Math.ceil(il / 7 * 8))
|
|
35
|
+
, ii = 0
|
|
36
|
+
, oi = 0
|
|
37
|
+
while (ii < il) {
|
|
38
|
+
// 0 1 2 3 4 5 6 7
|
|
39
|
+
// in 00000000 11111111 22222222 33333333 44444444 55555555 66666666
|
|
40
|
+
// out _0000000 _0111111 _1122222 _2223333 _3333444 _4444455 _5555556 _6666666
|
|
41
|
+
|
|
42
|
+
/* 0 */ out[oi++] = input[ii] >> 1 & 127
|
|
43
|
+
/* 1 */ out[oi++] = (input[ii++] << 6 | input[ii] >> 2) & 127
|
|
44
|
+
/* 2 */ out[oi++] = (input[ii++] << 5 | input[ii] >> 3) & 127
|
|
45
|
+
/* 3 */ out[oi++] = (input[ii++] << 4 | input[ii] >> 4) & 127
|
|
46
|
+
/* 4 */ out[oi++] = (input[ii++] << 3 | input[ii] >> 5) & 127
|
|
47
|
+
/* 5 */ out[oi++] = (input[ii++] << 2 | input[ii] >> 6) & 127
|
|
48
|
+
/* 6 */ out[oi++] = (input[ii++] << 1 | input[ii] >> 7) & 127
|
|
49
|
+
/* 7 */ out[oi++] = input[ii++] & 127
|
|
50
|
+
}
|
|
51
|
+
return new EncodeOutput(out)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {string} input
|
|
56
|
+
*/
|
|
57
|
+
export function decode(input) {
|
|
58
|
+
var il = input.length
|
|
59
|
+
, out = new Uint8Array(il / 8 * 7)
|
|
60
|
+
, ii = 0
|
|
61
|
+
, oi = 0
|
|
62
|
+
, cache
|
|
63
|
+
, next = () => (
|
|
64
|
+
(cache = input.charCodeAt(ii++)) > 127
|
|
65
|
+
? cache = 0 // In HTML, 0 is likely to be converted to 65533 (�)
|
|
66
|
+
: cache
|
|
67
|
+
)
|
|
68
|
+
while (ii < il) {
|
|
69
|
+
// 0 1 2 3 4 5 6 7
|
|
70
|
+
// in _0000000 _1111111 _2222222 _3333333 _4444444 _5555555 _6666666 _7777777
|
|
71
|
+
// out 00000001 11111122 22222333 33334444 44455555 55666666 67777777
|
|
72
|
+
|
|
73
|
+
/* 0 */ out[oi++] = next() << 1 | next() >> 6
|
|
74
|
+
/* 1 */ out[oi++] = cache << 2 | next() >> 5
|
|
75
|
+
/* 2 */ out[oi++] = cache << 3 | next() >> 4
|
|
76
|
+
/* 3 */ out[oi++] = cache << 4 | next() >> 3
|
|
77
|
+
/* 4 */ out[oi++] = cache << 5 | next() >> 2
|
|
78
|
+
/* 5 */ out[oi++] = cache << 6 | next() >> 1
|
|
79
|
+
/* 6 */ out[oi++] = cache << 7 | next()
|
|
80
|
+
}
|
|
81
|
+
return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default {
|
|
85
|
+
EncodeOutput,
|
|
86
|
+
encode,
|
|
87
|
+
decode
|
|
88
|
+
}
|
package/dist/browser.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
class EncodeOutput {
|
|
3
|
-
constructor(out) {
|
|
4
|
-
this.uint8Array = out;
|
|
5
|
-
}
|
|
6
|
-
toString() {
|
|
7
|
-
return new TextDecoder().decode(this.uint8Array);
|
|
8
|
-
}
|
|
9
|
-
toJSTemplateLiterals() {
|
|
10
|
-
return `\`${this.toString().replace(/[\r\\`]|\${|<\/script/g, (match) => (match == '\r'
|
|
11
|
-
? '\\r'
|
|
12
|
-
: match == '</script'
|
|
13
|
-
? '<\\/script'
|
|
14
|
-
: '\\' + match))}\``;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
self.base128 = {
|
|
18
|
-
EncodeOutput,
|
|
19
|
-
encode(input) {
|
|
20
|
-
if (typeof input == 'string')
|
|
21
|
-
input = new TextEncoder().encode(input);
|
|
22
|
-
var il = input.length, out = new Uint8Array(Math.ceil(il / 7 * 8)), ii = 0, oi = 0;
|
|
23
|
-
while (ii < il) {
|
|
24
|
-
// 0 1 2 3 4 5 6 7
|
|
25
|
-
// in 00000000 11111111 22222222 33333333 44444444 55555555 66666666
|
|
26
|
-
// out _0000000 _0111111 _1122222 _2223333 _3333444 _4444455 _5555556 _6666666
|
|
27
|
-
/* 0 */ out[oi++] = input[ii] >> 1 & 127;
|
|
28
|
-
/* 1 */ out[oi++] = (input[ii++] << 6 | input[ii] >> 2) & 127;
|
|
29
|
-
/* 2 */ out[oi++] = (input[ii++] << 5 | input[ii] >> 3) & 127;
|
|
30
|
-
/* 3 */ out[oi++] = (input[ii++] << 4 | input[ii] >> 4) & 127;
|
|
31
|
-
/* 4 */ out[oi++] = (input[ii++] << 3 | input[ii] >> 5) & 127;
|
|
32
|
-
/* 5 */ out[oi++] = (input[ii++] << 2 | input[ii] >> 6) & 127;
|
|
33
|
-
/* 6 */ out[oi++] = (input[ii++] << 1 | input[ii] >> 7) & 127;
|
|
34
|
-
/* 7 */ out[oi++] = input[ii++] & 127;
|
|
35
|
-
}
|
|
36
|
-
return new EncodeOutput(out);
|
|
37
|
-
},
|
|
38
|
-
decode(input) {
|
|
39
|
-
var il = input.length, out = new Uint8Array(Math.floor(il / 8 * 7)), ii = 0, oi = 0, cache, next = () => ((cache = input.charCodeAt(ii++)) > 127
|
|
40
|
-
? cache = 0 // In HTML, 0 is likely to be converted to 65533 (�)
|
|
41
|
-
: cache);
|
|
42
|
-
while (ii < il) {
|
|
43
|
-
// 0 1 2 3 4 5 6 7
|
|
44
|
-
// in _0000000 _1111111 _2222222 _3333333 _4444444 _5555555 _6666666 _7777777
|
|
45
|
-
// out 00000001 11111122 22222333 33334444 44455555 55666666 67777777
|
|
46
|
-
/* 0 */ out[oi++] = next() << 1 | next() >> 6;
|
|
47
|
-
/* 1 */ out[oi++] = cache << 2 | next() >> 5;
|
|
48
|
-
/* 2 */ out[oi++] = cache << 3 | next() >> 4;
|
|
49
|
-
/* 3 */ out[oi++] = cache << 4 | next() >> 3;
|
|
50
|
-
/* 4 */ out[oi++] = cache << 5 | next() >> 2;
|
|
51
|
-
/* 5 */ out[oi++] = cache << 6 | next() >> 1;
|
|
52
|
-
/* 6 */ out[oi++] = cache << 7 | next();
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export class EncodeOutput {
|
|
2
|
-
constructor(out) {
|
|
3
|
-
this.uint8Array = out;
|
|
4
|
-
}
|
|
5
|
-
toString() {
|
|
6
|
-
return new TextDecoder().decode(this.uint8Array);
|
|
7
|
-
}
|
|
8
|
-
toJSTemplateLiterals() {
|
|
9
|
-
return `\`${this.toString().replace(/[\r\\`]|\${|<\/script/g, (match) => (match == '\r'
|
|
10
|
-
? '\\r'
|
|
11
|
-
: match == '</script'
|
|
12
|
-
? '<\\/script'
|
|
13
|
-
: '\\' + match))}\``;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export function encode(input) {
|
|
17
|
-
if (typeof input == 'string')
|
|
18
|
-
input = new TextEncoder().encode(input);
|
|
19
|
-
var il = input.length, out = new Uint8Array(Math.ceil(il / 7 * 8)), ii = 0, oi = 0;
|
|
20
|
-
while (ii < il) {
|
|
21
|
-
// 0 1 2 3 4 5 6 7
|
|
22
|
-
// in 00000000 11111111 22222222 33333333 44444444 55555555 66666666
|
|
23
|
-
// out _0000000 _0111111 _1122222 _2223333 _3333444 _4444455 _5555556 _6666666
|
|
24
|
-
/* 0 */ out[oi++] = input[ii] >> 1 & 127;
|
|
25
|
-
/* 1 */ out[oi++] = (input[ii++] << 6 | input[ii] >> 2) & 127;
|
|
26
|
-
/* 2 */ out[oi++] = (input[ii++] << 5 | input[ii] >> 3) & 127;
|
|
27
|
-
/* 3 */ out[oi++] = (input[ii++] << 4 | input[ii] >> 4) & 127;
|
|
28
|
-
/* 4 */ out[oi++] = (input[ii++] << 3 | input[ii] >> 5) & 127;
|
|
29
|
-
/* 5 */ out[oi++] = (input[ii++] << 2 | input[ii] >> 6) & 127;
|
|
30
|
-
/* 6 */ out[oi++] = (input[ii++] << 1 | input[ii] >> 7) & 127;
|
|
31
|
-
/* 7 */ out[oi++] = input[ii++] & 127;
|
|
32
|
-
}
|
|
33
|
-
return new EncodeOutput(out);
|
|
34
|
-
}
|
|
35
|
-
export function decode(input) {
|
|
36
|
-
var il = input.length, out = new Uint8Array(Math.floor(il / 8 * 7)), ii = 0, oi = 0, cache, next = () => ((cache = input.charCodeAt(ii++)) > 127
|
|
37
|
-
? cache = 0 // In HTML, 0 is likely to be converted to 65533 (�)
|
|
38
|
-
: cache);
|
|
39
|
-
while (ii < il) {
|
|
40
|
-
// 0 1 2 3 4 5 6 7
|
|
41
|
-
// in _0000000 _1111111 _2222222 _3333333 _4444444 _5555555 _6666666 _7777777
|
|
42
|
-
// out 00000001 11111122 22222333 33334444 44455555 55666666 67777777
|
|
43
|
-
/* 0 */ out[oi++] = next() << 1 | next() >> 6;
|
|
44
|
-
/* 1 */ out[oi++] = cache << 2 | next() >> 5;
|
|
45
|
-
/* 2 */ out[oi++] = cache << 3 | next() >> 4;
|
|
46
|
-
/* 3 */ out[oi++] = cache << 4 | next() >> 3;
|
|
47
|
-
/* 4 */ out[oi++] = cache << 5 | next() >> 2;
|
|
48
|
-
/* 5 */ out[oi++] = cache << 6 | next() >> 1;
|
|
49
|
-
/* 6 */ out[oi++] = cache << 7 | next();
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
const base128 = {
|
|
54
|
-
EncodeOutput,
|
|
55
|
-
encode,
|
|
56
|
-
decode
|
|
57
|
-
};
|
|
58
|
-
export default base128;
|