base128-ascii 5.0.1 → 5.0.2
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 +26 -4
- package/main.js +7 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,10 +4,8 @@ Build for [vite-plugin-singlefile-compression](https://github.com/bddjr/vite-plu
|
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
|
7
|
-
### npm
|
|
8
|
-
|
|
9
7
|
```
|
|
10
|
-
npm i base128-ascii
|
|
8
|
+
npm i base128-ascii@latest
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
```js
|
|
@@ -25,16 +23,40 @@ const decodedBytes = base128.decode(eval(encodedTemplate))
|
|
|
25
23
|
|
|
26
24
|
## Effect
|
|
27
25
|
|
|
28
|
-
Encode this jpg file, use base128 is `
|
|
26
|
+
Encode this jpg file, use base128 is `112487 Bytes` smaller than base64:
|
|
29
27
|
|
|
30
28
|
```
|
|
31
29
|
screenshot-45.519.jpg
|
|
32
30
|
file length: 682086
|
|
33
31
|
|
|
34
32
|
base128:
|
|
33
|
+
time encode: 7.306ms
|
|
34
|
+
time toString: 0.168ms
|
|
35
|
+
time toJSTemplateLiterals: 1.876ms
|
|
35
36
|
toJSTemplateLiterals length: 796961
|
|
37
|
+
time eval: 6.242ms
|
|
38
|
+
time decode: 10.614ms
|
|
36
39
|
equal: true
|
|
37
40
|
|
|
38
41
|
base64:
|
|
39
42
|
encoded length: 909448
|
|
40
43
|
```
|
|
44
|
+
|
|
45
|
+
Encode `50MB` file, use base128 is `8180525 Bytes` smaller than base64:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
50MB
|
|
49
|
+
file length: 50000000
|
|
50
|
+
|
|
51
|
+
base128:
|
|
52
|
+
time encode: 67.717ms
|
|
53
|
+
time toString: 10.025ms
|
|
54
|
+
time toJSTemplateLiterals: 197.364ms
|
|
55
|
+
toJSTemplateLiterals length: 58486143
|
|
56
|
+
time eval: 1.083s
|
|
57
|
+
time decode: 171.262ms
|
|
58
|
+
equal: true
|
|
59
|
+
|
|
60
|
+
base64:
|
|
61
|
+
encoded length: 66666668
|
|
62
|
+
```
|
package/main.js
CHANGED
|
@@ -19,7 +19,11 @@ export class EncodeResult {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (
|
|
22
|
+
if (
|
|
23
|
+
typeof Buffer == 'function' &&
|
|
24
|
+
Buffer.prototype &&
|
|
25
|
+
typeof Buffer.prototype.latin1Slice == 'function'
|
|
26
|
+
) {
|
|
23
27
|
EncodeResult.prototype.toString = function () {
|
|
24
28
|
return Buffer.prototype.latin1Slice.call(this.bytes)
|
|
25
29
|
}
|
|
@@ -73,9 +77,8 @@ export function decode(input) {
|
|
|
73
77
|
// 0 1 2 3 4 5 6 7
|
|
74
78
|
// in _0000000 _1111111 _2222222 _3333333 _4444444 _5555555 _6666666 _7777777
|
|
75
79
|
// out 00000001 11111122 22222333 33334444 44455555 55666666 67777777
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
80
|
+
k || next(k = 7)
|
|
81
|
+
out[oi++] = cache << 8 - k | next() >> --k
|
|
79
82
|
}
|
|
80
83
|
return out
|
|
81
84
|
}
|