@yume-chan/adb 0.0.18 → 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 +21 -0
- package/CHANGELOG.md +11 -1
- package/esm/adb.d.ts +63 -60
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +257 -249
- 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.d.ts.map +1 -1
- 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 -46
- 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 +26 -26
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +22 -22
- package/esm/commands/power.js +48 -48
- package/esm/commands/reverse.d.ts +41 -28
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +125 -100
- 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 -80
- 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 -162
- 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 -47
- 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 -37
- 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 -22
- 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 -104
- 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 -149
- 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.js +248 -248
- 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.js +9 -9
- package/esm/packet.d.ts +45 -46
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +43 -48
- 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 -234
- 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 -118
- 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.js +246 -246
- 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 +11 -10
- package/src/adb.ts +47 -37
- package/src/auth.ts +7 -6
- package/src/backend.ts +4 -4
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +7 -8
- package/src/commands/reverse.ts +35 -10
- package/src/commands/subprocess/command.ts +12 -4
- package/src/commands/subprocess/index.ts +3 -3
- package/src/commands/subprocess/protocols/index.ts +3 -3
- package/src/commands/subprocess/protocols/none.ts +25 -11
- package/src/commands/subprocess/protocols/shell.ts +50 -28
- package/src/commands/subprocess/protocols/types.ts +8 -7
- package/src/commands/subprocess/utils.ts +1 -1
- package/src/commands/sync/index.ts +8 -7
- package/src/commands/sync/list.ts +42 -23
- package/src/commands/sync/pull.ts +40 -45
- package/src/commands/sync/push.ts +146 -39
- package/src/commands/sync/request.ts +20 -15
- package/src/commands/sync/response.ts +7 -6
- package/src/commands/sync/socket.ts +97 -0
- package/src/commands/sync/stat.ts +47 -42
- package/src/commands/sync/sync.ts +68 -108
- package/src/commands/tcpip.ts +5 -5
- package/src/features.ts +9 -6
- package/src/packet.ts +19 -34
- package/src/socket/dispatcher.ts +32 -47
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +26 -17
- package/src/utils/auto-reset-event.ts +14 -15
- package/src/utils/conditional-variable.ts +45 -0
- package/src/utils/index.ts +4 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/src/commands/install.ts +0 -40
package/esm/utils/base64.js
CHANGED
|
@@ -1,247 +1,247 @@
|
|
|
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
|
-
}
|
|
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
|
+
}
|
|
247
247
|
//# sourceMappingURL=base64.js.map
|
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/adb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "TypeScript implementation of Android Debug Bridge (ADB) protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adb",
|
|
@@ -26,20 +26,21 @@
|
|
|
26
26
|
"types": "esm/index.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@yume-chan/async": "^2.2.0",
|
|
29
|
-
"@yume-chan/dataview-bigint-polyfill": "^0.0.
|
|
30
|
-
"@yume-chan/event": "^0.0.
|
|
31
|
-
"@yume-chan/stream-extra": "^0.0.
|
|
32
|
-
"@yume-chan/struct": "^0.0.
|
|
29
|
+
"@yume-chan/dataview-bigint-polyfill": "^0.0.19",
|
|
30
|
+
"@yume-chan/event": "^0.0.19",
|
|
31
|
+
"@yume-chan/stream-extra": "^0.0.19",
|
|
32
|
+
"@yume-chan/struct": "^0.0.19",
|
|
33
33
|
"tslib": "^2.4.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@jest/globals": "^29.
|
|
37
|
-
"@types/node": "^18.
|
|
36
|
+
"@jest/globals": "^29.5.0",
|
|
37
|
+
"@types/node": "^18.15.0",
|
|
38
38
|
"@yume-chan/eslint-config": "^1.0.0",
|
|
39
39
|
"@yume-chan/tsconfig": "^1.0.0",
|
|
40
40
|
"cross-env": "^7.0.3",
|
|
41
|
-
"eslint": "^8.
|
|
42
|
-
"jest": "^29.
|
|
41
|
+
"eslint": "^8.36.0",
|
|
42
|
+
"jest": "^29.5.0",
|
|
43
|
+
"prettier": "^2.8.4",
|
|
43
44
|
"ts-jest": "^29.0.4",
|
|
44
45
|
"typescript": "^4.9.4"
|
|
45
46
|
},
|
|
@@ -47,6 +48,6 @@
|
|
|
47
48
|
"build": "tsc -b tsconfig.build.json",
|
|
48
49
|
"build:watch": "tsc -b tsconfig.build.json",
|
|
49
50
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
50
|
-
"lint": "eslint src/**/*.ts --fix"
|
|
51
|
+
"lint": "eslint src/**/*.ts --fix && prettier src/**/*.ts --write --tab-width 4"
|
|
51
52
|
}
|
|
52
53
|
}
|