@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
|
@@ -1,59 +1,60 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
new
|
|
59
|
-
|
|
1
|
+
import type { ReadableStream, WritableStream } from '@yume-chan/stream-extra';
|
|
2
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import type { Adb } from '../../../adb.js';
|
|
5
|
+
import type { AdbSocket } from '../../../socket/index.js';
|
|
6
|
+
|
|
7
|
+
export interface AdbSubprocessProtocol {
|
|
8
|
+
/**
|
|
9
|
+
* A WritableStream that writes to the `stdin` stream.
|
|
10
|
+
*/
|
|
11
|
+
readonly stdin: WritableStream<Uint8Array>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The `stdout` stream of the process.
|
|
15
|
+
*/
|
|
16
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `stderr` stream of the process.
|
|
20
|
+
*
|
|
21
|
+
* Note: Some `AdbSubprocessProtocol` doesn't separate `stdout` and `stderr`,
|
|
22
|
+
* All output will be sent to `stdout`.
|
|
23
|
+
*/
|
|
24
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A `Promise` that resolves to the exit code of the process.
|
|
28
|
+
*
|
|
29
|
+
* Note: Some `AdbSubprocessProtocol` doesn't support exit code,
|
|
30
|
+
* They will always resolve it with `0`.
|
|
31
|
+
*/
|
|
32
|
+
readonly exit: Promise<number>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resizes the current shell.
|
|
36
|
+
*
|
|
37
|
+
* Some `AdbSubprocessProtocol`s may not support resizing
|
|
38
|
+
* and will ignore calls to this method.
|
|
39
|
+
*/
|
|
40
|
+
resize(rows: number, cols: number): ValueOrPromise<void>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Kills the current process.
|
|
44
|
+
*/
|
|
45
|
+
kill(): ValueOrPromise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AdbSubprocessProtocolConstructor {
|
|
49
|
+
/** Returns `true` if the `adb` instance supports this shell */
|
|
50
|
+
isSupported(adb: Adb): ValueOrPromise<boolean>;
|
|
51
|
+
|
|
52
|
+
/** Spawns an executable in PTY (interactive) mode. */
|
|
53
|
+
pty(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
|
|
54
|
+
|
|
55
|
+
/** Spawns an executable and pipe the output. */
|
|
56
|
+
raw(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
|
|
57
|
+
|
|
58
|
+
/** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
|
|
59
|
+
new(socket: AdbSocket): AdbSubprocessProtocol;
|
|
60
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export function escapeArg(s: string) {
|
|
2
|
-
let result = '';
|
|
3
|
-
result += `'`;
|
|
4
|
-
|
|
5
|
-
let base = 0;
|
|
6
|
-
while (true) {
|
|
7
|
-
const found = s.indexOf(`'`, base);
|
|
8
|
-
if (found === -1) {
|
|
9
|
-
result += s.substring(base);
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
result += s.substring(base, found);
|
|
13
|
-
// a'b becomes a'\'b
|
|
14
|
-
result += String.raw`'\''`;
|
|
15
|
-
base = found + 1;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
result += `'`;
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
1
|
+
export function escapeArg(s: string) {
|
|
2
|
+
let result = '';
|
|
3
|
+
result += `'`;
|
|
4
|
+
|
|
5
|
+
let base = 0;
|
|
6
|
+
while (true) {
|
|
7
|
+
const found = s.indexOf(`'`, base);
|
|
8
|
+
if (found === -1) {
|
|
9
|
+
result += s.substring(base);
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
result += s.substring(base, found);
|
|
13
|
+
// a'b becomes a'\'b
|
|
14
|
+
result += String.raw`'\''`;
|
|
15
|
+
base = found + 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
result += `'`;
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './list.js';
|
|
2
|
-
export * from './pull.js';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './stat.js';
|
|
7
|
-
export * from './sync.js';
|
|
1
|
+
export * from './list.js';
|
|
2
|
+
export * from './pull.js';
|
|
3
|
+
export * from './push.js';
|
|
4
|
+
export * from './request.js';
|
|
5
|
+
export * from './response.js';
|
|
6
|
+
export * from './stat.js';
|
|
7
|
+
export * from './sync.js';
|
|
@@ -1,86 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await adbSyncWriteRequest(writer, requestId, path);
|
|
57
|
-
|
|
58
|
-
while (true) {
|
|
59
|
-
const response = await adbSyncReadResponse(stream, responseType);
|
|
60
|
-
switch (response.id) {
|
|
61
|
-
case AdbSyncResponseId.Entry:
|
|
62
|
-
yield {
|
|
63
|
-
mode: response.mode,
|
|
64
|
-
size: BigInt(response.size),
|
|
65
|
-
mtime: BigInt(response.mtime),
|
|
66
|
-
get type() { return response.type; },
|
|
67
|
-
get permission() { return response.permission; },
|
|
68
|
-
name: response.name,
|
|
69
|
-
};
|
|
70
|
-
break;
|
|
71
|
-
case AdbSyncResponseId.Entry2:
|
|
72
|
-
// `LST2` can return error codes for failed `lstat` calls.
|
|
73
|
-
// `LIST` just ignores them.
|
|
74
|
-
// But they only contain `name` so still pretty useless.
|
|
75
|
-
if (response.error !== 0) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
yield response;
|
|
79
|
-
break;
|
|
80
|
-
case AdbSyncResponseId.Done:
|
|
81
|
-
return;
|
|
82
|
-
default:
|
|
83
|
-
throw new Error('Unexpected response id');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
import type { BufferedReadableStream, WritableStreamDefaultWriter } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
5
|
+
import { adbSyncReadResponses, AdbSyncResponseId } from './response.js';
|
|
6
|
+
import { AdbSyncLstatResponse, AdbSyncStatResponse, type AdbSyncStat } from './stat.js';
|
|
7
|
+
|
|
8
|
+
export interface AdbSyncEntry extends AdbSyncStat {
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const AdbSyncEntryResponse =
|
|
13
|
+
new Struct({ littleEndian: true })
|
|
14
|
+
.fields(AdbSyncLstatResponse)
|
|
15
|
+
.uint32('nameLength')
|
|
16
|
+
.string('name', { lengthField: 'nameLength' })
|
|
17
|
+
.extra({ id: AdbSyncResponseId.Entry as const });
|
|
18
|
+
|
|
19
|
+
export type AdbSyncEntryResponse = typeof AdbSyncEntryResponse['TDeserializeResult'];
|
|
20
|
+
|
|
21
|
+
export const AdbSyncEntry2Response =
|
|
22
|
+
new Struct({ littleEndian: true })
|
|
23
|
+
.fields(AdbSyncStatResponse)
|
|
24
|
+
.uint32('nameLength')
|
|
25
|
+
.string('name', { lengthField: 'nameLength' })
|
|
26
|
+
.extra({ id: AdbSyncResponseId.Entry2 as const });
|
|
27
|
+
|
|
28
|
+
export type AdbSyncEntry2Response = typeof AdbSyncEntry2Response['TDeserializeResult'];
|
|
29
|
+
|
|
30
|
+
export async function* adbSyncOpenDir(
|
|
31
|
+
stream: BufferedReadableStream,
|
|
32
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
33
|
+
path: string,
|
|
34
|
+
v2: boolean,
|
|
35
|
+
): AsyncGenerator<AdbSyncEntry, void, void> {
|
|
36
|
+
if (v2) {
|
|
37
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.List2, path);
|
|
38
|
+
yield* adbSyncReadResponses(stream, AdbSyncResponseId.Entry2, AdbSyncEntry2Response);
|
|
39
|
+
} else {
|
|
40
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.List, path);
|
|
41
|
+
for await (const item of adbSyncReadResponses(stream, AdbSyncResponseId.Entry, AdbSyncEntryResponse)) {
|
|
42
|
+
// Convert to same format as `AdbSyncEntry2Response` for easier consumption.
|
|
43
|
+
// However it will add some overhead.
|
|
44
|
+
yield {
|
|
45
|
+
mode: item.mode,
|
|
46
|
+
size: BigInt(item.size),
|
|
47
|
+
mtime: BigInt(item.mtime),
|
|
48
|
+
get type() { return item.type; },
|
|
49
|
+
get permission() { return item.permission; },
|
|
50
|
+
name: item.name,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,46 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await adbSyncWriteRequest(writer, AdbSyncRequestId.Receive, path);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
1
|
+
import { BufferedReadableStream, ReadableStream, WritableStreamDefaultWriter } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
5
|
+
import { adbSyncReadResponses, AdbSyncResponseId } from './response.js';
|
|
6
|
+
|
|
7
|
+
export const AdbSyncDataResponse =
|
|
8
|
+
new Struct({ littleEndian: true })
|
|
9
|
+
.uint32('dataLength')
|
|
10
|
+
.uint8Array('data', { lengthField: 'dataLength' })
|
|
11
|
+
.extra({ id: AdbSyncResponseId.Data as const });
|
|
12
|
+
|
|
13
|
+
export type AdbSyncDataResponse = typeof AdbSyncDataResponse['TDeserializeResult'];
|
|
14
|
+
|
|
15
|
+
export function adbSyncPull(
|
|
16
|
+
stream: BufferedReadableStream,
|
|
17
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
18
|
+
path: string,
|
|
19
|
+
): ReadableStream<Uint8Array> {
|
|
20
|
+
let generator!: AsyncGenerator<AdbSyncDataResponse, void, void>;
|
|
21
|
+
return new ReadableStream<Uint8Array>({
|
|
22
|
+
async start() {
|
|
23
|
+
// TODO: If `ReadableStream.from(AsyncGenerator)` is added to spec, use it instead.
|
|
24
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Receive, path);
|
|
25
|
+
generator = adbSyncReadResponses(stream, AdbSyncResponseId.Data, AdbSyncDataResponse);
|
|
26
|
+
},
|
|
27
|
+
async pull(controller) {
|
|
28
|
+
const { done, value } = await generator.next();
|
|
29
|
+
if (done) {
|
|
30
|
+
controller.close();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
controller.enqueue(value.data);
|
|
34
|
+
},
|
|
35
|
+
cancel() {
|
|
36
|
+
try {
|
|
37
|
+
generator.return();
|
|
38
|
+
} catch { }
|
|
39
|
+
throw new Error(`Sync commands can't be canceled.`);
|
|
40
|
+
},
|
|
41
|
+
}, {
|
|
42
|
+
highWaterMark: 16 * 1024,
|
|
43
|
+
size(chunk) { return chunk.byteLength; }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
await adbSyncWriteRequest(writer, AdbSyncRequestId.
|
|
30
|
-
},
|
|
31
|
-
async
|
|
32
|
-
await adbSyncWriteRequest(writer, AdbSyncRequestId.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
new ChunkStream(packetSize)
|
|
40
|
-
);
|
|
41
|
-
}
|
|
1
|
+
import { BufferedReadableStream, ChunkStream, pipeFrom, WritableStream, WritableStreamDefaultWriter } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
5
|
+
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
6
|
+
import { LinuxFileType } from './stat.js';
|
|
7
|
+
|
|
8
|
+
export const AdbSyncOkResponse =
|
|
9
|
+
new Struct({ littleEndian: true })
|
|
10
|
+
.uint32('unused');
|
|
11
|
+
|
|
12
|
+
export const ADB_SYNC_MAX_PACKET_SIZE = 64 * 1024;
|
|
13
|
+
|
|
14
|
+
export function adbSyncPush(
|
|
15
|
+
stream: BufferedReadableStream,
|
|
16
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
17
|
+
filename: string,
|
|
18
|
+
mode: number = (LinuxFileType.File << 12) | 0o666,
|
|
19
|
+
mtime: number = (Date.now() / 1000) | 0,
|
|
20
|
+
packetSize: number = ADB_SYNC_MAX_PACKET_SIZE,
|
|
21
|
+
): WritableStream<Uint8Array> {
|
|
22
|
+
return pipeFrom(
|
|
23
|
+
new WritableStream<Uint8Array>({
|
|
24
|
+
async start() {
|
|
25
|
+
const pathAndMode = `${filename},${mode.toString()}`;
|
|
26
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Send, pathAndMode);
|
|
27
|
+
},
|
|
28
|
+
async write(chunk) {
|
|
29
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Data, chunk);
|
|
30
|
+
},
|
|
31
|
+
async close() {
|
|
32
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Done, mtime);
|
|
33
|
+
await adbSyncReadResponse(stream, AdbSyncResponseId.Ok, AdbSyncOkResponse);
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
new ChunkStream(packetSize)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
import type { WritableStreamDefaultWriter } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import { encodeUtf8 } from '../../utils/index.js';
|
|
5
|
+
|
|
6
|
+
export enum AdbSyncRequestId {
|
|
7
|
+
List = 'LIST',
|
|
8
|
+
List2 = 'LIS2',
|
|
9
|
+
Send = 'SEND',
|
|
10
|
+
Lstat = 'STAT',
|
|
11
|
+
Stat = 'STA2',
|
|
12
|
+
Lstat2 = 'LST2',
|
|
13
|
+
Data = 'DATA',
|
|
14
|
+
Done = 'DONE',
|
|
15
|
+
Receive = 'RECV',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const AdbSyncNumberRequest =
|
|
19
|
+
new Struct({ littleEndian: true })
|
|
20
|
+
.string('id', { length: 4 })
|
|
21
|
+
.uint32('arg');
|
|
22
|
+
|
|
23
|
+
export const AdbSyncDataRequest =
|
|
24
|
+
new Struct({ littleEndian: true })
|
|
25
|
+
.fields(AdbSyncNumberRequest)
|
|
26
|
+
.uint8Array('data', { lengthField: 'arg' });
|
|
27
|
+
|
|
28
|
+
export async function adbSyncWriteRequest(
|
|
29
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
30
|
+
id: AdbSyncRequestId | string,
|
|
31
|
+
value: number | string | Uint8Array
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
let buffer: Uint8Array;
|
|
34
|
+
if (typeof value === 'number') {
|
|
35
|
+
buffer = AdbSyncNumberRequest.serialize({
|
|
36
|
+
id,
|
|
37
|
+
arg: value,
|
|
38
|
+
});
|
|
39
|
+
} else if (typeof value === 'string') {
|
|
40
|
+
buffer = AdbSyncDataRequest.serialize({
|
|
41
|
+
id,
|
|
42
|
+
data: encodeUtf8(value),
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
buffer = AdbSyncDataRequest.serialize({
|
|
46
|
+
id,
|
|
47
|
+
data: value,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
await writer.write(buffer);
|
|
51
|
+
}
|