@yume-chan/adb 0.0.15 → 0.0.17
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 +33 -0
- package/CHANGELOG.md +18 -1
- package/LICENSE +21 -21
- package/README.md +247 -247
- package/esm/adb.d.ts +15 -3
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +18 -6
- package/esm/adb.js.map +1 -1
- package/esm/auth.d.ts.map +1 -1
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +2 -2
- package/esm/backend.d.ts.map +1 -1
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +17 -1
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +4 -15
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/install.d.ts +2 -2
- package/esm/commands/install.d.ts.map +1 -1
- package/esm/commands/install.js +3 -2
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +1 -1
- package/esm/commands/power.js +1 -1
- package/esm/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +9 -9
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +52 -0
- package/esm/commands/subprocess/command.d.ts.map +1 -0
- package/esm/commands/subprocess/command.js +83 -0
- package/esm/commands/subprocess/command.js.map +1 -0
- package/esm/commands/subprocess/index.d.ts +1 -53
- package/esm/commands/subprocess/index.d.ts.map +1 -1
- package/esm/commands/subprocess/index.js +1 -85
- package/esm/commands/subprocess/index.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts +5 -4
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +11 -8
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +4 -4
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +6 -6
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +7 -7
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/index.d.ts +1 -1
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +1 -1
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +2 -2
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +15 -43
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +3 -2
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +15 -17
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +2 -2
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +2 -5
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +1 -1
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +1 -1
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +4 -9
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +32 -23
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +3 -3
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +13 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +2 -2
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +7 -5
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/crypto.js +1 -1
- package/esm/crypto.js.map +1 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +1 -1
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +1 -1
- package/esm/packet.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +11 -3
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +19 -11
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +1 -1
- package/esm/socket/index.d.ts.map +1 -1
- package/esm/socket/index.js +1 -1
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +9 -4
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +20 -10
- package/esm/socket/socket.js.map +1 -1
- package/esm/utils/base64.d.ts +23 -0
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +6 -0
- package/esm/utils/base64.js.map +1 -1
- package/package.json +13 -14
- package/src/adb.ts +285 -273
- package/src/auth.ts +174 -173
- package/src/backend.ts +12 -11
- package/src/commands/base.ts +12 -11
- package/src/commands/framebuffer.ts +78 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +32 -30
- package/src/commands/power.ts +54 -54
- package/src/commands/reverse.ts +141 -140
- package/src/commands/subprocess/command.ts +131 -0
- package/src/commands/subprocess/index.ts +3 -139
- package/src/commands/subprocess/protocols/none.ts +73 -68
- package/src/commands/subprocess/protocols/shell.ts +191 -190
- package/src/commands/subprocess/protocols/types.ts +60 -59
- package/src/commands/subprocess/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +54 -86
- package/src/commands/sync/pull.ts +45 -46
- package/src/commands/sync/push.ts +38 -41
- package/src/commands/sync/request.ts +51 -50
- package/src/commands/sync/response.ts +68 -64
- package/src/commands/sync/stat.ts +129 -150
- package/src/commands/sync/sync.ts +182 -181
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +296 -296
- package/src/features.ts +9 -9
- package/src/index.ts +10 -11
- package/src/packet.ts +80 -80
- package/src/socket/dispatcher.ts +310 -304
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +156 -144
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +329 -306
- package/src/utils/index.ts +3 -3
- package/tsconfig.build.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/commands/subprocess/legacy.d.ts +0 -35
- package/esm/commands/subprocess/legacy.d.ts.map +0 -1
- package/esm/commands/subprocess/legacy.js +0 -53
- package/esm/commands/subprocess/legacy.js.map +0 -1
- package/esm/commands/subprocess/protocol.d.ts +0 -39
- package/esm/commands/subprocess/protocol.d.ts.map +0 -1
- package/esm/commands/subprocess/protocol.js +0 -157
- package/esm/commands/subprocess/protocol.js.map +0 -1
- package/esm/commands/subprocess/types.d.ts +0 -50
- package/esm/commands/subprocess/types.d.ts.map +0 -1
- package/esm/commands/subprocess/types.js +0 -2
- package/esm/commands/subprocess/types.js.map +0 -1
- package/esm/socket/controller.d.ts +0 -37
- package/esm/socket/controller.d.ts.map +0 -1
- package/esm/socket/controller.js +0 -66
- package/esm/socket/controller.js.map +0 -1
- package/esm/stream/buffered.d.ts +0 -35
- package/esm/stream/buffered.d.ts.map +0 -1
- package/esm/stream/buffered.js +0 -123
- package/esm/stream/buffered.js.map +0 -1
- package/esm/stream/detect.bak.d.ts +0 -240
- package/esm/stream/detect.bak.d.ts.map +0 -1
- package/esm/stream/detect.bak.js +0 -60
- package/esm/stream/detect.bak.js.map +0 -1
- package/esm/stream/detect.d.ts +0 -2
- package/esm/stream/detect.d.ts.map +0 -1
- package/esm/stream/detect.js +0 -5
- package/esm/stream/detect.js.map +0 -1
- package/esm/stream/detect.native.d.ts +0 -240
- package/esm/stream/detect.native.d.ts.map +0 -1
- package/esm/stream/detect.native.js +0 -60
- package/esm/stream/detect.native.js.map +0 -1
- package/esm/stream/detect.polyfill.d.ts +0 -18
- package/esm/stream/detect.polyfill.d.ts.map +0 -1
- package/esm/stream/detect.polyfill.js +0 -9
- package/esm/stream/detect.polyfill.js.map +0 -1
- package/esm/stream/index.d.ts +0 -4
- package/esm/stream/index.d.ts.map +0 -1
- package/esm/stream/index.js +0 -4
- package/esm/stream/index.js.map +0 -1
- package/esm/stream/transform.d.ts +0 -104
- package/esm/stream/transform.d.ts.map +0 -1
- package/esm/stream/transform.js +0 -373
- package/esm/stream/transform.js.map +0 -1
- package/esm/utils/encoding.d.ts +0 -3
- package/esm/utils/encoding.d.ts.map +0 -1
- package/esm/utils/encoding.js +0 -11
- package/esm/utils/encoding.js.map +0 -1
- package/src/stream/buffered.ts +0 -147
- package/src/stream/detect.native.ts +0 -362
- package/src/stream/detect.polyfill.ts +0 -28
- package/src/stream/detect.ts +0 -5
- package/src/stream/index.ts +0 -3
- package/src/stream/transform.ts +0 -447
- package/tsconfig.test.json +0 -10
package/esm/stream/transform.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
-
import { decodeUtf8 } from "../utils/index.js";
|
|
3
|
-
import { BufferedStream, BufferedStreamEndedError } from "./buffered.js";
|
|
4
|
-
import { AbortController, ReadableStream, TransformStream, WritableStream } from "./detect.js";
|
|
5
|
-
/**
|
|
6
|
-
* A factory for creating a duplex stream.
|
|
7
|
-
*
|
|
8
|
-
* It can create multiple `ReadableStream`s and `WritableStream`s,
|
|
9
|
-
* when any of them is closed, all other streams will be closed as well.
|
|
10
|
-
*/
|
|
11
|
-
export class DuplexStreamFactory {
|
|
12
|
-
readableControllers = [];
|
|
13
|
-
writers = [];
|
|
14
|
-
_writableClosed = false;
|
|
15
|
-
get writableClosed() { return this._writableClosed; }
|
|
16
|
-
_closed = new PromiseResolver();
|
|
17
|
-
get closed() { return this._closed.promise; }
|
|
18
|
-
options;
|
|
19
|
-
constructor(options) {
|
|
20
|
-
this.options = options ?? {};
|
|
21
|
-
}
|
|
22
|
-
wrapReadable(readable) {
|
|
23
|
-
return new WrapReadableStream({
|
|
24
|
-
start: (controller) => {
|
|
25
|
-
this.readableControllers.push(controller);
|
|
26
|
-
return readable;
|
|
27
|
-
},
|
|
28
|
-
cancel: async () => {
|
|
29
|
-
// cancel means the local peer closes the connection first.
|
|
30
|
-
await this.close();
|
|
31
|
-
},
|
|
32
|
-
close: async () => {
|
|
33
|
-
// stream end means the remote peer closed the connection first.
|
|
34
|
-
await this.dispose();
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
createWritable(stream) {
|
|
39
|
-
const writer = stream.getWriter();
|
|
40
|
-
this.writers.push(writer);
|
|
41
|
-
// `WritableStream` has no way to tell if the remote peer has closed the connection.
|
|
42
|
-
// So it only triggers `close`.
|
|
43
|
-
return new WritableStream({
|
|
44
|
-
write: async (chunk) => {
|
|
45
|
-
await writer.ready;
|
|
46
|
-
await writer.write(chunk);
|
|
47
|
-
},
|
|
48
|
-
abort: async (reason) => {
|
|
49
|
-
await writer.abort(reason);
|
|
50
|
-
await this.close();
|
|
51
|
-
},
|
|
52
|
-
close: async () => {
|
|
53
|
-
try {
|
|
54
|
-
await writer.close();
|
|
55
|
-
}
|
|
56
|
-
catch { }
|
|
57
|
-
await this.close();
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async close() {
|
|
62
|
-
if (this._writableClosed) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this._writableClosed = true;
|
|
66
|
-
if (await this.options.close?.() !== false) {
|
|
67
|
-
// `close` can return `false` to disable automatic `dispose`.
|
|
68
|
-
await this.dispose();
|
|
69
|
-
}
|
|
70
|
-
for (const writer of this.writers) {
|
|
71
|
-
try {
|
|
72
|
-
await writer.close();
|
|
73
|
-
}
|
|
74
|
-
catch { }
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async dispose() {
|
|
78
|
-
this._writableClosed = true;
|
|
79
|
-
this._closed.resolve();
|
|
80
|
-
for (const controller of this.readableControllers) {
|
|
81
|
-
try {
|
|
82
|
-
controller.close();
|
|
83
|
-
}
|
|
84
|
-
catch { }
|
|
85
|
-
}
|
|
86
|
-
await this.options.dispose?.();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export class DecodeUtf8Stream extends TransformStream {
|
|
90
|
-
constructor() {
|
|
91
|
-
super({
|
|
92
|
-
transform(chunk, controller) {
|
|
93
|
-
controller.enqueue(decodeUtf8(chunk));
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export class GatherStringStream extends WritableStream {
|
|
99
|
-
// Optimization: rope (concat strings) is faster than `[].join('')`
|
|
100
|
-
_result = '';
|
|
101
|
-
get result() { return this._result; }
|
|
102
|
-
constructor() {
|
|
103
|
-
super({
|
|
104
|
-
write: (chunk) => {
|
|
105
|
-
this._result += chunk;
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// TODO: StructTransformStream: Looking for better implementation
|
|
111
|
-
export class StructDeserializeStream {
|
|
112
|
-
_readable;
|
|
113
|
-
get readable() { return this._readable; }
|
|
114
|
-
_writable;
|
|
115
|
-
get writable() { return this._writable; }
|
|
116
|
-
constructor(struct) {
|
|
117
|
-
// Convert incoming chunks to a `BufferedStream`
|
|
118
|
-
let incomingStreamController;
|
|
119
|
-
const incomingStream = new BufferedStream(new PushReadableStream(controller => incomingStreamController = controller));
|
|
120
|
-
this._readable = new ReadableStream({
|
|
121
|
-
async pull(controller) {
|
|
122
|
-
try {
|
|
123
|
-
const value = await struct.deserialize(incomingStream);
|
|
124
|
-
controller.enqueue(value);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
if (e instanceof BufferedStreamEndedError) {
|
|
128
|
-
controller.close();
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
throw e;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
this._writable = new WritableStream({
|
|
136
|
-
async write(chunk) {
|
|
137
|
-
await incomingStreamController.enqueue(chunk);
|
|
138
|
-
},
|
|
139
|
-
abort() {
|
|
140
|
-
incomingStreamController.close();
|
|
141
|
-
},
|
|
142
|
-
close() {
|
|
143
|
-
incomingStreamController.close();
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
export class StructSerializeStream extends TransformStream {
|
|
149
|
-
constructor(struct) {
|
|
150
|
-
super({
|
|
151
|
-
transform(chunk, controller) {
|
|
152
|
-
controller.enqueue(struct.serialize(chunk));
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async function getWrappedWritableStream(wrapper) {
|
|
158
|
-
if ('start' in wrapper) {
|
|
159
|
-
return await wrapper.start();
|
|
160
|
-
}
|
|
161
|
-
else if (typeof wrapper === 'function') {
|
|
162
|
-
return await wrapper();
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
// Can't use `wrapper instanceof WritableStream`
|
|
166
|
-
// Because we want to be compatible with any WritableStream-like objects
|
|
167
|
-
return wrapper;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
export class WrapWritableStream extends WritableStream {
|
|
171
|
-
writable;
|
|
172
|
-
writer;
|
|
173
|
-
constructor(wrapper) {
|
|
174
|
-
super({
|
|
175
|
-
start: async () => {
|
|
176
|
-
// `start` is invoked before `ReadableStream`'s constructor finish,
|
|
177
|
-
// so using `this` synchronously causes
|
|
178
|
-
// "Must call super constructor in derived class before accessing 'this' or returning from derived constructor".
|
|
179
|
-
// Queue a microtask to avoid this.
|
|
180
|
-
await Promise.resolve();
|
|
181
|
-
this.writable = await getWrappedWritableStream(wrapper);
|
|
182
|
-
this.writer = this.writable.getWriter();
|
|
183
|
-
},
|
|
184
|
-
write: async (chunk) => {
|
|
185
|
-
// Maintain back pressure
|
|
186
|
-
await this.writer.ready;
|
|
187
|
-
await this.writer.write(chunk);
|
|
188
|
-
},
|
|
189
|
-
abort: async (reason) => {
|
|
190
|
-
await this.writer.abort(reason);
|
|
191
|
-
if ('close' in wrapper) {
|
|
192
|
-
await wrapper.close?.();
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
close: async () => {
|
|
196
|
-
// Close the inner stream first.
|
|
197
|
-
// Usually the inner stream is a logical sub-stream over the outer stream,
|
|
198
|
-
// closing the outer stream first will make the inner stream incapable of
|
|
199
|
-
// sending data in its `close` handler.
|
|
200
|
-
await this.writer.close();
|
|
201
|
-
if ('close' in wrapper) {
|
|
202
|
-
await wrapper.close?.();
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function getWrappedReadableStream(wrapper, controller) {
|
|
209
|
-
if ('start' in wrapper) {
|
|
210
|
-
return wrapper.start(controller);
|
|
211
|
-
}
|
|
212
|
-
else if (typeof wrapper === 'function') {
|
|
213
|
-
return wrapper(controller);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
// Can't use `wrapper instanceof ReadableStream`
|
|
217
|
-
// Because we want to be compatible with any ReadableStream-like objects
|
|
218
|
-
return wrapper;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* This class has multiple usages:
|
|
223
|
-
*
|
|
224
|
-
* 1. Get notified when the stream is cancelled or closed.
|
|
225
|
-
* 2. Synchronously create a `ReadableStream` by asynchronously return another `ReadableStream`.
|
|
226
|
-
* 3. Convert native `ReadableStream`s to polyfilled ones so they can `pipe` between.
|
|
227
|
-
*/
|
|
228
|
-
export class WrapReadableStream extends ReadableStream {
|
|
229
|
-
readable;
|
|
230
|
-
reader;
|
|
231
|
-
constructor(wrapper) {
|
|
232
|
-
super({
|
|
233
|
-
start: async (controller) => {
|
|
234
|
-
// `start` is invoked before `ReadableStream`'s constructor finish,
|
|
235
|
-
// so using `this` synchronously causes
|
|
236
|
-
// "Must call super constructor in derived class before accessing 'this' or returning from derived constructor".
|
|
237
|
-
// Queue a microtask to avoid this.
|
|
238
|
-
await Promise.resolve();
|
|
239
|
-
this.readable = await getWrappedReadableStream(wrapper, controller);
|
|
240
|
-
this.reader = this.readable.getReader();
|
|
241
|
-
},
|
|
242
|
-
cancel: async (reason) => {
|
|
243
|
-
await this.reader.cancel(reason);
|
|
244
|
-
if ('cancel' in wrapper) {
|
|
245
|
-
await wrapper.cancel?.(reason);
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
pull: async (controller) => {
|
|
249
|
-
const result = await this.reader.read();
|
|
250
|
-
if (result.done) {
|
|
251
|
-
controller.close();
|
|
252
|
-
if ('close' in wrapper) {
|
|
253
|
-
await wrapper.close?.();
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
controller.enqueue(result.value);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
export class ChunkStream extends TransformStream {
|
|
264
|
-
constructor(size) {
|
|
265
|
-
super({
|
|
266
|
-
transform(chunk, controller) {
|
|
267
|
-
for (let start = 0; start < chunk.byteLength;) {
|
|
268
|
-
const end = start + size;
|
|
269
|
-
controller.enqueue(chunk.subarray(start, end));
|
|
270
|
-
start = end;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function* splitLines(text) {
|
|
277
|
-
let start = 0;
|
|
278
|
-
while (true) {
|
|
279
|
-
const index = text.indexOf('\n', start);
|
|
280
|
-
if (index === -1) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
const line = text.substring(start, index);
|
|
284
|
-
yield line;
|
|
285
|
-
start = index + 1;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
export class SplitLineStream extends TransformStream {
|
|
289
|
-
constructor() {
|
|
290
|
-
super({
|
|
291
|
-
transform(chunk, controller) {
|
|
292
|
-
for (const line of splitLines(chunk)) {
|
|
293
|
-
controller.enqueue(line);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Create a new `WritableStream` that, when written to, will write that chunk to
|
|
301
|
-
* `pair.writable`, when pipe `pair.readable` to `writable`.
|
|
302
|
-
*
|
|
303
|
-
* It's the opposite of `ReadableStream.pipeThrough`.
|
|
304
|
-
*
|
|
305
|
-
* @param writable The `WritableStream` to write to.
|
|
306
|
-
* @param pair A `TransformStream` that converts chunks.
|
|
307
|
-
* @returns A new `WritableStream`.
|
|
308
|
-
*/
|
|
309
|
-
export function pipeFrom(writable, pair) {
|
|
310
|
-
const writer = pair.writable.getWriter();
|
|
311
|
-
const pipe = pair.readable
|
|
312
|
-
.pipeTo(writable);
|
|
313
|
-
return new WritableStream({
|
|
314
|
-
async write(chunk) {
|
|
315
|
-
await writer.ready;
|
|
316
|
-
await writer.write(chunk);
|
|
317
|
-
},
|
|
318
|
-
async close() {
|
|
319
|
-
await writer.close();
|
|
320
|
-
await pipe;
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
export class InspectStream extends TransformStream {
|
|
325
|
-
constructor(callback) {
|
|
326
|
-
super({
|
|
327
|
-
transform(chunk, controller) {
|
|
328
|
-
callback(chunk);
|
|
329
|
-
controller.enqueue(chunk);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
export class PushReadableStream extends ReadableStream {
|
|
335
|
-
constructor(source, strategy) {
|
|
336
|
-
let waterMarkLow;
|
|
337
|
-
const canceled = new AbortController();
|
|
338
|
-
super({
|
|
339
|
-
start: (controller) => {
|
|
340
|
-
source({
|
|
341
|
-
abortSignal: canceled.signal,
|
|
342
|
-
async enqueue(chunk) {
|
|
343
|
-
// Only when the stream is errored, `desiredSize` will be `null`.
|
|
344
|
-
// But since `null <= 0` is `true`
|
|
345
|
-
// (`null <= 0` is evaluated as `!(null > 0)` => `!false` => `true`),
|
|
346
|
-
// not handling it will cause a deadlock.
|
|
347
|
-
if ((controller.desiredSize ?? 1) <= 0) {
|
|
348
|
-
waterMarkLow = new PromiseResolver();
|
|
349
|
-
await waterMarkLow.promise;
|
|
350
|
-
}
|
|
351
|
-
// `controller.enqueue` will throw error for us
|
|
352
|
-
// if the stream is already errored.
|
|
353
|
-
controller.enqueue(chunk);
|
|
354
|
-
},
|
|
355
|
-
close() {
|
|
356
|
-
controller.close();
|
|
357
|
-
},
|
|
358
|
-
error(e) {
|
|
359
|
-
controller.error(e);
|
|
360
|
-
},
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
pull: () => {
|
|
364
|
-
waterMarkLow?.resolve();
|
|
365
|
-
},
|
|
366
|
-
cancel: async (reason) => {
|
|
367
|
-
canceled.abort();
|
|
368
|
-
waterMarkLow?.reject(reason);
|
|
369
|
-
},
|
|
370
|
-
}, strategy);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/stream/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,eAAe,EAAe,cAAc,EAA+B,eAAe,EAAE,cAAc,EAAsH,MAAM,aAAa,CAAC;AAQ7P;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IACpB,mBAAmB,GAAyC,EAAE,CAAC;IAC/D,OAAO,GAAqC,EAAE,CAAC;IAE/C,eAAe,GAAG,KAAK,CAAC;IAChC,IAAW,cAAc,KAAK,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IAEpD,OAAO,GAAG,IAAI,eAAe,EAAQ,CAAC;IAC9C,IAAW,MAAM,KAAK,OAAO,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E,MAAM,GAAG,UAAU,CAEpD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,GAAG,MAAM,CAExE"}
|
package/esm/utils/encoding.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error @types/node missing `TextEncoder`
|
|
2
|
-
const Utf8Encoder = new TextEncoder();
|
|
3
|
-
// @ts-expect-error @types/node missing `TextDecoder`
|
|
4
|
-
const Utf8Decoder = new TextDecoder();
|
|
5
|
-
export function encodeUtf8(input) {
|
|
6
|
-
return Utf8Encoder.encode(input);
|
|
7
|
-
}
|
|
8
|
-
export function decodeUtf8(buffer) {
|
|
9
|
-
return Utf8Decoder.decode(buffer);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=encoding.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,qDAAqD;AACrD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,UAAU,UAAU,CAAC,KAAa;IACpC,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAqC;IAC5D,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
package/src/stream/buffered.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import type { StructAsyncDeserializeStream } from '@yume-chan/struct';
|
|
2
|
-
import type { AdbSocket, AdbSocketInfo } from '../socket/index.js';
|
|
3
|
-
import type { ReadableStream, ReadableStreamDefaultReader } from './detect.js';
|
|
4
|
-
import { PushReadableStream } from "./transform.js";
|
|
5
|
-
|
|
6
|
-
export class BufferedStreamEndedError extends Error {
|
|
7
|
-
public constructor() {
|
|
8
|
-
super('Stream ended');
|
|
9
|
-
|
|
10
|
-
// Fix Error's prototype chain when compiling to ES5
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class BufferedStream {
|
|
16
|
-
private buffer: Uint8Array | undefined;
|
|
17
|
-
|
|
18
|
-
protected readonly stream: ReadableStream<Uint8Array>;
|
|
19
|
-
|
|
20
|
-
protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
21
|
-
|
|
22
|
-
public constructor(stream: ReadableStream<Uint8Array>) {
|
|
23
|
-
this.stream = stream;
|
|
24
|
-
this.reader = stream.getReader();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param length
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
public async read(length: number): Promise<Uint8Array> {
|
|
33
|
-
let array: Uint8Array;
|
|
34
|
-
let index: number;
|
|
35
|
-
if (this.buffer) {
|
|
36
|
-
const buffer = this.buffer;
|
|
37
|
-
if (buffer.byteLength > length) {
|
|
38
|
-
this.buffer = buffer.subarray(length);
|
|
39
|
-
return buffer.subarray(0, length);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
array = new Uint8Array(length);
|
|
43
|
-
array.set(buffer);
|
|
44
|
-
index = buffer.byteLength;
|
|
45
|
-
this.buffer = undefined;
|
|
46
|
-
} else {
|
|
47
|
-
const { done, value } = await this.reader.read();
|
|
48
|
-
if (done) {
|
|
49
|
-
throw new BufferedStreamEndedError();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (value.byteLength === length) {
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (value.byteLength > length) {
|
|
57
|
-
this.buffer = value.subarray(length);
|
|
58
|
-
return value.subarray(0, length);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
array = new Uint8Array(length);
|
|
62
|
-
array.set(value);
|
|
63
|
-
index = value.byteLength;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
while (index < length) {
|
|
67
|
-
const left = length - index;
|
|
68
|
-
|
|
69
|
-
const { done, value } = await this.reader.read();
|
|
70
|
-
if (done) {
|
|
71
|
-
throw new BufferedStreamEndedError();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (value.byteLength === left) {
|
|
75
|
-
array.set(value, index);
|
|
76
|
-
return array;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (value.byteLength > left) {
|
|
80
|
-
array.set(value.subarray(0, left), index);
|
|
81
|
-
this.buffer = value.subarray(left);
|
|
82
|
-
return array;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
array.set(value, index);
|
|
86
|
-
index += value.byteLength;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return array;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Return a readable stream with unconsumed data (if any) and
|
|
94
|
-
* all data from the wrapped stream.
|
|
95
|
-
* @returns A `ReadableStream`
|
|
96
|
-
*/
|
|
97
|
-
public release(): ReadableStream<Uint8Array> {
|
|
98
|
-
if (this.buffer) {
|
|
99
|
-
return new PushReadableStream<Uint8Array>(async controller => {
|
|
100
|
-
// Put the remaining data back to the stream
|
|
101
|
-
await controller.enqueue(this.buffer!);
|
|
102
|
-
|
|
103
|
-
// Manually pipe the stream
|
|
104
|
-
while (true) {
|
|
105
|
-
try {
|
|
106
|
-
const { done, value } = await this.reader.read();
|
|
107
|
-
if (done) {
|
|
108
|
-
controller.close();
|
|
109
|
-
break;
|
|
110
|
-
} else {
|
|
111
|
-
await controller.enqueue(value);
|
|
112
|
-
}
|
|
113
|
-
} catch (e) {
|
|
114
|
-
controller.error(e);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
} else {
|
|
120
|
-
// Simply release the reader and return the stream
|
|
121
|
-
this.reader.releaseLock();
|
|
122
|
-
return this.stream;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public async close() {
|
|
127
|
-
await this.reader.cancel();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export class AdbBufferedStream
|
|
132
|
-
extends BufferedStream
|
|
133
|
-
implements AdbSocketInfo, StructAsyncDeserializeStream {
|
|
134
|
-
protected readonly socket: AdbSocket;
|
|
135
|
-
|
|
136
|
-
public get localId() { return this.socket.localId; }
|
|
137
|
-
public get remoteId() { return this.socket.remoteId; }
|
|
138
|
-
public get localCreated() { return this.socket.localCreated; }
|
|
139
|
-
public get serviceString() { return this.socket.serviceString; }
|
|
140
|
-
|
|
141
|
-
public get writable() { return this.socket.writable; }
|
|
142
|
-
|
|
143
|
-
public constructor(socket: AdbSocket) {
|
|
144
|
-
super(socket.readable);
|
|
145
|
-
this.socket = socket;
|
|
146
|
-
}
|
|
147
|
-
}
|