@yume-chan/adb 0.0.17 → 0.0.19
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/CHANGELOG.json +27 -0
- package/CHANGELOG.md +16 -1
- package/LICENSE +1 -1
- package/esm/adb.d.ts +63 -60
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +257 -229
- package/esm/adb.js.map +1 -1
- package/esm/auth.d.ts +51 -51
- package/esm/auth.d.ts.map +1 -1
- package/esm/auth.js +95 -96
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +8 -8
- package/esm/backend.d.ts.map +1 -1
- package/esm/backend.js +1 -1
- package/esm/commands/base.d.ts +6 -6
- package/esm/commands/base.js +8 -8
- package/esm/commands/framebuffer.d.ts +53 -53
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +46 -47
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +7 -8
- package/esm/commands/index.d.ts.map +1 -1
- package/esm/commands/index.js +7 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +9 -3
- package/esm/commands/install.d.ts.map +1 -1
- package/esm/commands/install.js +27 -21
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +22 -22
- package/esm/commands/power.d.ts.map +1 -1
- package/esm/commands/power.js +48 -44
- package/esm/commands/power.js.map +1 -1
- package/esm/commands/reverse.d.ts +41 -28
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +125 -98
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +57 -51
- package/esm/commands/subprocess/command.d.ts.map +1 -1
- package/esm/commands/subprocess/command.js +86 -82
- package/esm/commands/subprocess/command.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +3 -3
- package/esm/commands/subprocess/index.js +3 -3
- package/esm/commands/subprocess/protocols/index.d.ts +3 -3
- package/esm/commands/subprocess/protocols/index.js +3 -3
- package/esm/commands/subprocess/protocols/none.d.ts +35 -35
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +65 -55
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +39 -38
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +166 -154
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +49 -49
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/types.js +1 -1
- package/esm/commands/subprocess/utils.d.ts +1 -1
- package/esm/commands/subprocess/utils.js +18 -18
- package/esm/commands/sync/index.d.ts +8 -7
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +8 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +42 -40
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +67 -35
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +13 -11
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +35 -36
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +46 -7
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +89 -23
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +26 -23
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +40 -42
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +19 -19
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +54 -54
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +27 -0
- package/esm/commands/sync/socket.d.ts.map +1 -0
- package/esm/commands/sync/socket.js +66 -0
- package/esm/commands/sync/socket.js.map +1 -0
- package/esm/commands/sync/stat.d.ts +72 -72
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +116 -94
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +72 -60
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +127 -148
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +5 -5
- package/esm/commands/tcpip.js +18 -18
- package/esm/crypto.d.ts +36 -36
- package/esm/crypto.d.ts.map +1 -1
- package/esm/crypto.js +248 -238
- package/esm/crypto.js.map +1 -1
- package/esm/features.d.ts +10 -7
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +13 -10
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +9 -9
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +9 -9
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +45 -46
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +43 -46
- package/esm/packet.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +59 -59
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +223 -231
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +2 -2
- package/esm/socket/index.js +2 -2
- package/esm/socket/socket.d.ts +59 -59
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +118 -98
- package/esm/socket/socket.js.map +1 -1
- package/esm/utils/auto-reset-event.d.ts +9 -9
- package/esm/utils/auto-reset-event.d.ts.map +1 -1
- package/esm/utils/auto-reset-event.js +33 -33
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +27 -27
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +246 -245
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/conditional-variable.d.ts +9 -0
- package/esm/utils/conditional-variable.d.ts.map +1 -0
- package/esm/utils/conditional-variable.js +34 -0
- package/esm/utils/conditional-variable.js.map +1 -0
- package/esm/utils/index.d.ts +4 -3
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +4 -3
- package/esm/utils/index.js.map +1 -1
- package/package.json +17 -13
- package/src/adb.ts +160 -101
- package/src/auth.ts +31 -22
- package/src/backend.ts +6 -4
- package/src/commands/base.ts +2 -2
- package/src/commands/framebuffer.ts +37 -41
- package/src/commands/index.ts +7 -8
- package/src/commands/power.ts +15 -11
- package/src/commands/reverse.ts +74 -30
- package/src/commands/subprocess/command.ts +34 -23
- package/src/commands/subprocess/index.ts +3 -3
- package/src/commands/subprocess/protocols/index.ts +3 -3
- package/src/commands/subprocess/protocols/none.ts +26 -11
- package/src/commands/subprocess/protocols/shell.ts +110 -56
- package/src/commands/subprocess/protocols/types.ts +10 -6
- package/src/commands/subprocess/utils.ts +1 -1
- package/src/commands/sync/index.ts +8 -7
- package/src/commands/sync/list.ts +74 -28
- package/src/commands/sync/pull.ts +49 -37
- package/src/commands/sync/push.ts +153 -32
- package/src/commands/sync/request.ts +37 -34
- package/src/commands/sync/response.ts +34 -27
- package/src/commands/sync/socket.ts +97 -0
- package/src/commands/sync/stat.ts +98 -70
- package/src/commands/sync/sync.ts +78 -97
- package/src/commands/tcpip.ts +5 -5
- package/src/crypto.ts +60 -32
- package/src/features.ts +9 -6
- package/src/index.ts +9 -10
- package/src/packet.ts +41 -46
- package/src/socket/dispatcher.ts +130 -108
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +84 -34
- package/src/utils/auto-reset-event.ts +16 -17
- package/src/utils/base64.ts +51 -41
- package/src/utils/conditional-variable.ts +45 -0
- package/src/utils/index.ts +4 -3
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/src/commands/install.ts +0 -32
package/esm/utils/base64.js
CHANGED
|
@@ -1,246 +1,247 @@
|
|
|
1
|
-
//
|
|
2
|
-
const charToIndex =
|
|
3
|
-
const indexToChar = [];
|
|
4
|
-
const paddingChar =
|
|
5
|
-
function addRange(start, end) {
|
|
6
|
-
const charCodeStart = start.charCodeAt(0);
|
|
7
|
-
const charCodeEnd = end.charCodeAt(0);
|
|
8
|
-
for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
|
|
9
|
-
charToIndex[
|
|
10
|
-
indexToChar.push(charCode);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
addRange(
|
|
14
|
-
addRange(
|
|
15
|
-
addRange(
|
|
16
|
-
addRange(
|
|
17
|
-
addRange(
|
|
18
|
-
/**
|
|
19
|
-
* Calculate the required length of the output buffer for the given input length.
|
|
20
|
-
*
|
|
21
|
-
* @param inputLength Length of the input in bytes
|
|
22
|
-
* @returns Length of the output in bytes
|
|
23
|
-
*/
|
|
24
|
-
export function calculateBase64EncodedLength(inputLength) {
|
|
25
|
-
const remainder = inputLength % 3;
|
|
26
|
-
const paddingLength = remainder !== 0 ? 3 - remainder : 0;
|
|
27
|
-
return [(inputLength + paddingLength) / 3 * 4, paddingLength];
|
|
28
|
-
}
|
|
29
|
-
export function encodeBase64(input, output) {
|
|
30
|
-
const [outputLength, paddingLength] = calculateBase64EncodedLength(input.length);
|
|
31
|
-
if (!output) {
|
|
32
|
-
output = new Uint8Array(outputLength);
|
|
33
|
-
encodeForward(input, output, paddingLength);
|
|
34
|
-
return output;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (output.length < outputLength) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
}
|
|
40
|
-
output = output.subarray(0, outputLength);
|
|
41
|
-
// When input and output are on same ArrayBuffer,
|
|
42
|
-
// we check if it's possible to encode in-place.
|
|
43
|
-
if (input.buffer !== output.buffer) {
|
|
44
|
-
encodeForward(input, output, paddingLength);
|
|
45
|
-
}
|
|
46
|
-
else if (output.byteOffset + output.length - (paddingLength + 1) <=
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
// |
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
// |
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
// |
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
// |
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
outputIndex
|
|
102
|
-
|
|
103
|
-
outputIndex
|
|
104
|
-
|
|
105
|
-
outputIndex
|
|
106
|
-
|
|
107
|
-
outputIndex
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
outputIndex
|
|
116
|
-
|
|
117
|
-
outputIndex
|
|
118
|
-
|
|
119
|
-
outputIndex
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
outputIndex
|
|
133
|
-
|
|
134
|
-
outputIndex
|
|
135
|
-
|
|
136
|
-
outputIndex
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
outputIndex
|
|
150
|
-
|
|
151
|
-
outputIndex
|
|
152
|
-
|
|
153
|
-
outputIndex
|
|
154
|
-
|
|
155
|
-
outputIndex
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
outputIndex
|
|
168
|
-
|
|
169
|
-
outputIndex
|
|
170
|
-
|
|
171
|
-
outputIndex
|
|
172
|
-
|
|
173
|
-
outputIndex
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
outputIndex
|
|
190
|
-
|
|
191
|
-
outputIndex
|
|
192
|
-
|
|
193
|
-
outputIndex
|
|
194
|
-
|
|
195
|
-
outputIndex
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
dIndex
|
|
223
|
-
|
|
224
|
-
dIndex
|
|
225
|
-
|
|
226
|
-
dIndex
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
dIndex
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
1
|
+
// Array is faster than object literal or `Map`
|
|
2
|
+
const charToIndex = [];
|
|
3
|
+
const indexToChar = [];
|
|
4
|
+
const paddingChar = "=".charCodeAt(0);
|
|
5
|
+
function addRange(start, end) {
|
|
6
|
+
const charCodeStart = start.charCodeAt(0);
|
|
7
|
+
const charCodeEnd = end.charCodeAt(0);
|
|
8
|
+
for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
|
|
9
|
+
charToIndex[charCode] = indexToChar.length;
|
|
10
|
+
indexToChar.push(charCode);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
addRange("A", "Z");
|
|
14
|
+
addRange("a", "z");
|
|
15
|
+
addRange("0", "9");
|
|
16
|
+
addRange("+", "+");
|
|
17
|
+
addRange("/", "/");
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the required length of the output buffer for the given input length.
|
|
20
|
+
*
|
|
21
|
+
* @param inputLength Length of the input in bytes
|
|
22
|
+
* @returns Length of the output in bytes
|
|
23
|
+
*/
|
|
24
|
+
export function calculateBase64EncodedLength(inputLength) {
|
|
25
|
+
const remainder = inputLength % 3;
|
|
26
|
+
const paddingLength = remainder !== 0 ? 3 - remainder : 0;
|
|
27
|
+
return [((inputLength + paddingLength) / 3) * 4, paddingLength];
|
|
28
|
+
}
|
|
29
|
+
export function encodeBase64(input, output) {
|
|
30
|
+
const [outputLength, paddingLength] = calculateBase64EncodedLength(input.length);
|
|
31
|
+
if (!output) {
|
|
32
|
+
output = new Uint8Array(outputLength);
|
|
33
|
+
encodeForward(input, output, paddingLength);
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (output.length < outputLength) {
|
|
38
|
+
throw new Error("output buffer is too small");
|
|
39
|
+
}
|
|
40
|
+
output = output.subarray(0, outputLength);
|
|
41
|
+
// When input and output are on same ArrayBuffer,
|
|
42
|
+
// we check if it's possible to encode in-place.
|
|
43
|
+
if (input.buffer !== output.buffer) {
|
|
44
|
+
encodeForward(input, output, paddingLength);
|
|
45
|
+
}
|
|
46
|
+
else if (output.byteOffset + output.length - (paddingLength + 1) <=
|
|
47
|
+
input.byteOffset + input.length) {
|
|
48
|
+
// Output ends before input ends
|
|
49
|
+
// So output won't catch up with input.
|
|
50
|
+
// Depends on padding length,
|
|
51
|
+
// it's possible to write 1-3 bytes after input ends.
|
|
52
|
+
// spell: disable-next-line
|
|
53
|
+
// | aaaaaabb | | | |
|
|
54
|
+
// | aaaaaa | bb0000 | = | = |
|
|
55
|
+
//
|
|
56
|
+
// spell: disable-next-line
|
|
57
|
+
// | aaaaaabb | bbbbcccc | | |
|
|
58
|
+
// | aaaaaa | bbbbbb | cccc00 | = |
|
|
59
|
+
//
|
|
60
|
+
// spell: disable-next-line
|
|
61
|
+
// | aaaaaabb | bbbbcccc | ccdddddd | |
|
|
62
|
+
// | aaaaaa | bbbbbb | cccccc | dddddd |
|
|
63
|
+
// Must encode forwards.
|
|
64
|
+
encodeForward(input, output, paddingLength);
|
|
65
|
+
}
|
|
66
|
+
else if (output.byteOffset >= input.byteOffset - 1) {
|
|
67
|
+
// Output starts after input starts
|
|
68
|
+
// So in backwards, output can't catch up with input.
|
|
69
|
+
// Because first 3 bytes becomes 4 bytes,
|
|
70
|
+
// it's possible to write 1 byte before input starts.
|
|
71
|
+
// spell: disable-next-line
|
|
72
|
+
// | | aaaaaabb | bbbbcccc | ccdddddd |
|
|
73
|
+
// | aaaaaa | bbbbbb | cccccc | dddddd |
|
|
74
|
+
// Must encode backwards.
|
|
75
|
+
encodeBackward(input, output, paddingLength);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Input is in the middle of output,
|
|
79
|
+
// not possible to read neither first or last three bytes,
|
|
80
|
+
throw new Error("input and output cannot overlap");
|
|
81
|
+
}
|
|
82
|
+
return outputLength;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function encodeForward(input, output, paddingLength) {
|
|
86
|
+
let inputIndex = 0;
|
|
87
|
+
let outputIndex = 0;
|
|
88
|
+
while (inputIndex < input.length - 2) {
|
|
89
|
+
/* cspell: disable-next-line */
|
|
90
|
+
// aaaaaabb
|
|
91
|
+
const x = input[inputIndex];
|
|
92
|
+
inputIndex += 1;
|
|
93
|
+
/* cspell: disable-next-line */
|
|
94
|
+
// bbbbcccc
|
|
95
|
+
const y = input[inputIndex];
|
|
96
|
+
inputIndex += 1;
|
|
97
|
+
/* cspell: disable-next-line */
|
|
98
|
+
// ccdddddd
|
|
99
|
+
const z = input[inputIndex];
|
|
100
|
+
inputIndex += 1;
|
|
101
|
+
output[outputIndex] = indexToChar[x >> 2];
|
|
102
|
+
outputIndex += 1;
|
|
103
|
+
output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
|
|
104
|
+
outputIndex += 1;
|
|
105
|
+
output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
|
|
106
|
+
outputIndex += 1;
|
|
107
|
+
output[outputIndex] = indexToChar[z & 0b111111];
|
|
108
|
+
outputIndex += 1;
|
|
109
|
+
}
|
|
110
|
+
if (paddingLength === 2) {
|
|
111
|
+
/* cspell: disable-next-line */
|
|
112
|
+
// aaaaaabb
|
|
113
|
+
const x = input[inputIndex];
|
|
114
|
+
inputIndex += 1;
|
|
115
|
+
output[outputIndex] = indexToChar[x >> 2];
|
|
116
|
+
outputIndex += 1;
|
|
117
|
+
output[outputIndex] = indexToChar[(x & 0b11) << 4];
|
|
118
|
+
outputIndex += 1;
|
|
119
|
+
output[outputIndex] = paddingChar;
|
|
120
|
+
outputIndex += 1;
|
|
121
|
+
output[outputIndex] = paddingChar;
|
|
122
|
+
}
|
|
123
|
+
else if (paddingLength === 1) {
|
|
124
|
+
/* cspell: disable-next-line */
|
|
125
|
+
// aaaaaabb
|
|
126
|
+
const x = input[inputIndex];
|
|
127
|
+
inputIndex += 1;
|
|
128
|
+
/* cspell: disable-next-line */
|
|
129
|
+
// bbbbcccc
|
|
130
|
+
const y = input[inputIndex];
|
|
131
|
+
inputIndex += 1;
|
|
132
|
+
output[outputIndex] = indexToChar[x >> 2];
|
|
133
|
+
outputIndex += 1;
|
|
134
|
+
output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
|
|
135
|
+
outputIndex += 1;
|
|
136
|
+
output[outputIndex] = indexToChar[(y & 0b1111) << 2];
|
|
137
|
+
outputIndex += 1;
|
|
138
|
+
output[outputIndex] = paddingChar;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function encodeBackward(input, output, paddingLength) {
|
|
142
|
+
let inputIndex = input.length - 1;
|
|
143
|
+
let outputIndex = output.length - 1;
|
|
144
|
+
if (paddingLength === 2) {
|
|
145
|
+
/* cspell: disable-next-line */
|
|
146
|
+
// aaaaaabb
|
|
147
|
+
const x = input[inputIndex];
|
|
148
|
+
inputIndex -= 1;
|
|
149
|
+
output[outputIndex] = paddingChar;
|
|
150
|
+
outputIndex -= 1;
|
|
151
|
+
output[outputIndex] = paddingChar;
|
|
152
|
+
outputIndex -= 1;
|
|
153
|
+
output[outputIndex] = indexToChar[(x & 0b11) << 4];
|
|
154
|
+
outputIndex -= 1;
|
|
155
|
+
output[outputIndex] = indexToChar[x >> 2];
|
|
156
|
+
outputIndex -= 1;
|
|
157
|
+
}
|
|
158
|
+
else if (paddingLength === 1) {
|
|
159
|
+
/* cspell: disable-next-line */
|
|
160
|
+
// bbbbcccc
|
|
161
|
+
const y = input[inputIndex];
|
|
162
|
+
inputIndex -= 1;
|
|
163
|
+
/* cspell: disable-next-line */
|
|
164
|
+
// aaaaaabb
|
|
165
|
+
const x = input[inputIndex];
|
|
166
|
+
inputIndex -= 1;
|
|
167
|
+
output[outputIndex] = paddingChar;
|
|
168
|
+
outputIndex -= 1;
|
|
169
|
+
output[outputIndex] = indexToChar[(y & 0b1111) << 2];
|
|
170
|
+
outputIndex -= 1;
|
|
171
|
+
output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
|
|
172
|
+
outputIndex -= 1;
|
|
173
|
+
output[outputIndex] = indexToChar[x >> 2];
|
|
174
|
+
outputIndex -= 1;
|
|
175
|
+
}
|
|
176
|
+
while (inputIndex >= 0) {
|
|
177
|
+
/* cspell: disable-next-line */
|
|
178
|
+
// ccdddddd
|
|
179
|
+
const z = input[inputIndex];
|
|
180
|
+
inputIndex -= 1;
|
|
181
|
+
/* cspell: disable-next-line */
|
|
182
|
+
// bbbbcccc
|
|
183
|
+
const y = input[inputIndex];
|
|
184
|
+
inputIndex -= 1;
|
|
185
|
+
/* cspell: disable-next-line */
|
|
186
|
+
// aaaaaabb
|
|
187
|
+
const x = input[inputIndex];
|
|
188
|
+
inputIndex -= 1;
|
|
189
|
+
output[outputIndex] = indexToChar[z & 0b111111];
|
|
190
|
+
outputIndex -= 1;
|
|
191
|
+
output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
|
|
192
|
+
outputIndex -= 1;
|
|
193
|
+
output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
|
|
194
|
+
outputIndex -= 1;
|
|
195
|
+
output[outputIndex] = indexToChar[x >> 2];
|
|
196
|
+
outputIndex -= 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
export function decodeBase64(input) {
|
|
200
|
+
let padding;
|
|
201
|
+
if (input[input.length - 2] === "=") {
|
|
202
|
+
padding = 2;
|
|
203
|
+
}
|
|
204
|
+
else if (input[input.length - 1] === "=") {
|
|
205
|
+
padding = 1;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
padding = 0;
|
|
209
|
+
}
|
|
210
|
+
const result = new Uint8Array((input.length / 4) * 3 - padding);
|
|
211
|
+
let sIndex = 0;
|
|
212
|
+
let dIndex = 0;
|
|
213
|
+
while (sIndex < input.length - (padding !== 0 ? 4 : 0)) {
|
|
214
|
+
const a = charToIndex[input.charCodeAt(sIndex)];
|
|
215
|
+
sIndex += 1;
|
|
216
|
+
const b = charToIndex[input.charCodeAt(sIndex)];
|
|
217
|
+
sIndex += 1;
|
|
218
|
+
const c = charToIndex[input.charCodeAt(sIndex)];
|
|
219
|
+
sIndex += 1;
|
|
220
|
+
const d = charToIndex[input.charCodeAt(sIndex)];
|
|
221
|
+
sIndex += 1;
|
|
222
|
+
result[dIndex] = (a << 2) | ((b & 48) >> 4);
|
|
223
|
+
dIndex += 1;
|
|
224
|
+
result[dIndex] = ((b & 0b1111) << 4) | ((c & 60) >> 2);
|
|
225
|
+
dIndex += 1;
|
|
226
|
+
result[dIndex] = ((c & 0b11) << 6) | d;
|
|
227
|
+
dIndex += 1;
|
|
228
|
+
}
|
|
229
|
+
if (padding === 1) {
|
|
230
|
+
const a = charToIndex[input.charCodeAt(sIndex)];
|
|
231
|
+
sIndex += 1;
|
|
232
|
+
const b = charToIndex[input.charCodeAt(sIndex)];
|
|
233
|
+
sIndex += 1;
|
|
234
|
+
const c = charToIndex[input.charCodeAt(sIndex)];
|
|
235
|
+
result[dIndex] = (a << 2) | ((b & 48) >> 4);
|
|
236
|
+
dIndex += 1;
|
|
237
|
+
result[dIndex] = ((b & 0b1111) << 4) | ((c & 60) >> 2);
|
|
238
|
+
}
|
|
239
|
+
else if (padding === 2) {
|
|
240
|
+
const a = charToIndex[input.charCodeAt(sIndex)];
|
|
241
|
+
sIndex += 1;
|
|
242
|
+
const b = charToIndex[input.charCodeAt(sIndex)];
|
|
243
|
+
result[dIndex] = (a << 2) | ((b & 48) >> 4);
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
246
247
|
//# sourceMappingURL=base64.js.map
|
package/esm/utils/base64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3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AI,OAAO,KAAK,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAE,CAAC;QACjD,MAAM,IAAI,CAAC,CAAC;QAEZ,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAE,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACtD;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Disposable } from "@yume-chan/event";
|
|
2
|
+
export declare class ConditionalVariable implements Disposable {
|
|
3
|
+
private _locked;
|
|
4
|
+
private readonly _queue;
|
|
5
|
+
wait(condition: () => boolean): Promise<void>;
|
|
6
|
+
notifyOne(): void;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=conditional-variable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-variable.d.ts","sourceRoot":"","sources":["../../src/utils/conditional-variable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAOnD,qBAAa,mBAAoB,YAAW,UAAU;IAClD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAEnC,IAAI,CAAC,SAAS,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa7C,SAAS;IAWT,OAAO,IAAI,IAAI;CAQzB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
export class ConditionalVariable {
|
|
3
|
+
_locked = false;
|
|
4
|
+
_queue = [];
|
|
5
|
+
wait(condition) {
|
|
6
|
+
if (!this._locked) {
|
|
7
|
+
this._locked = true;
|
|
8
|
+
if (this._queue.length === 0 && condition()) {
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const resolver = new PromiseResolver();
|
|
13
|
+
this._queue.push({ condition, resolver });
|
|
14
|
+
return resolver.promise;
|
|
15
|
+
}
|
|
16
|
+
notifyOne() {
|
|
17
|
+
const entry = this._queue.shift();
|
|
18
|
+
if (entry) {
|
|
19
|
+
if (entry.condition()) {
|
|
20
|
+
entry.resolver.resolve();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this._locked = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
dispose() {
|
|
28
|
+
for (const item of this._queue) {
|
|
29
|
+
item.resolver.reject(new Error("The ConditionalVariable has been disposed"));
|
|
30
|
+
}
|
|
31
|
+
this._queue.length = 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=conditional-variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-variable.js","sourceRoot":"","sources":["../../src/utils/conditional-variable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQnD,MAAM,OAAO,mBAAmB;IACpB,OAAO,GAAG,KAAK,CAAC;IACP,MAAM,GAAgB,EAAE,CAAC;IAEnC,IAAI,CAAC,SAAwB;QAChC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,EAAE,EAAE;gBACzC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;aAC5B;SACJ;QAED,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAQ,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC5B,CAAC;IAEM,SAAS;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,KAAK,EAAE;YACP,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE;gBACnB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;aAC5B;SACJ;aAAM;YACH,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;SACxB;IACL,CAAC;IAEM,OAAO;QACV,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;YAC5B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAChB,IAAI,KAAK,CAAC,2CAA2C,CAAC,CACzD,CAAC;SACL;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;CACJ"}
|
package/esm/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { decodeUtf8, encodeUtf8 } from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export { decodeUtf8, encodeUtf8 } from "@yume-chan/struct";
|
|
2
|
+
export * from "./auto-reset-event.js";
|
|
3
|
+
export * from "./base64.js";
|
|
4
|
+
export * from "./conditional-variable.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC"}
|
package/esm/utils/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { decodeUtf8, encodeUtf8 } from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export { decodeUtf8, encodeUtf8 } from "@yume-chan/struct";
|
|
2
|
+
export * from "./auto-reset-event.js";
|
|
3
|
+
export * from "./base64.js";
|
|
4
|
+
export * from "./conditional-variable.js";
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/esm/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC"}
|