@yume-chan/adb 0.0.10 → 0.0.13
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 +50 -0
- package/CHANGELOG.md +29 -1
- package/LICENSE +1 -1
- package/README.md +71 -51
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +149 -136
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +11 -11
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +72 -110
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +19 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +49 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +56 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +88 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +35 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +53 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +39 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +157 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/protocols/index.d.ts +4 -0
- package/esm/commands/subprocess/protocols/index.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/index.js +4 -0
- package/esm/commands/subprocess/protocols/index.js.map +1 -0
- package/esm/commands/subprocess/protocols/none.d.ts +35 -0
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/none.js +53 -0
- package/esm/commands/subprocess/protocols/none.js.map +1 -0
- package/esm/commands/subprocess/protocols/shell.d.ts +39 -0
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/shell.js +155 -0
- package/esm/commands/subprocess/protocols/shell.js.map +1 -0
- package/esm/commands/subprocess/protocols/types.d.ts +50 -0
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess/protocols}/types.js +0 -0
- package/esm/commands/subprocess/protocols/types.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +50 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/subprocess/types.js +2 -0
- package/esm/commands/{shell → subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +41 -0
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +52 -20
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +4 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +25 -27
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +4 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +17 -20
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +16 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +38 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +61 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +122 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +37 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +77 -62
- package/esm/crypto.js.map +1 -1
- package/esm/features.d.ts +8 -0
- package/esm/features.d.ts.map +1 -0
- package/esm/features.js +7 -3
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +47 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +27 -52
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +44 -0
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +146 -165
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +46 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +77 -13
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +2 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +5 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +9 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +402 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +1 -1
- package/esm/utils/encoding.js.map +1 -1
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -5
- package/esm/utils/index.js.map +1 -1
- package/package.json +50 -44
- package/src/adb.ts +177 -150
- package/src/auth.ts +37 -30
- package/src/backend.ts +3 -12
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +24 -15
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +10 -8
- package/src/commands/subprocess/index.ts +139 -0
- package/src/commands/subprocess/protocols/index.ts +3 -0
- package/src/commands/subprocess/protocols/none.ts +68 -0
- package/src/commands/subprocess/protocols/shell.ts +190 -0
- package/src/commands/subprocess/protocols/types.ts +59 -0
- package/src/commands/{shell → subprocess}/utils.ts +0 -0
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +56 -9
- package/src/commands/sync/pull.ts +27 -18
- package/src/commands/sync/push.ts +25 -30
- package/src/commands/sync/request.ts +8 -7
- package/src/commands/sync/response.ts +12 -6
- package/src/commands/sync/stat.ts +43 -14
- package/src/commands/sync/sync.ts +102 -34
- package/src/commands/tcpip.ts +3 -3
- package/src/crypto.ts +95 -84
- package/src/features.ts +6 -2
- package/src/index.ts +11 -10
- package/src/packet.ts +49 -53
- package/src/socket/dispatcher.ts +110 -109
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +125 -17
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +28 -0
- package/src/stream/detect.ts +5 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +483 -0
- package/src/utils/auto-reset-event.ts +1 -1
- package/src/utils/base64.ts +161 -129
- package/src/utils/index.ts +3 -5
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -13
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -46
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -38
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -45
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -47
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts +0 -17
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -24
- package/dts/crypto.d.ts.map +0 -1
- package/dts/features.d.ts +0 -6
- package/dts/features.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts +0 -53
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -28
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/encoding.d.ts +0 -3
- package/dts/utils/encoding.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -6
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -62
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -49
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -106
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -67
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -87
- package/src/commands/shell/legacy.ts +0 -59
- package/src/commands/shell/protocol.ts +0 -121
- package/src/commands/shell/types.ts +0 -55
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -92
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/encoding.ts +0 -13
- package/src/utils/event-queue.ts +0 -145
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import Struct from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
-
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
5
|
-
import { AdbSyncLstatResponse } from './stat';
|
|
2
|
+
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
4
|
+
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
5
|
+
import { AdbSyncLstatResponse, AdbSyncStatResponse, type AdbSyncStat } from './stat.js';
|
|
6
|
+
|
|
7
|
+
export interface AdbSyncEntry extends AdbSyncStat {
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
6
10
|
|
|
7
11
|
export const AdbSyncEntryResponse =
|
|
8
12
|
new Struct({ littleEndian: true })
|
|
@@ -13,21 +17,64 @@ export const AdbSyncEntryResponse =
|
|
|
13
17
|
|
|
14
18
|
export type AdbSyncEntryResponse = typeof AdbSyncEntryResponse['TDeserializeResult'];
|
|
15
19
|
|
|
16
|
-
const
|
|
20
|
+
export const AdbSyncEntry2Response =
|
|
21
|
+
new Struct({ littleEndian: true })
|
|
22
|
+
.fields(AdbSyncStatResponse)
|
|
23
|
+
.uint32('nameLength')
|
|
24
|
+
.string('name', { lengthField: 'nameLength' })
|
|
25
|
+
.extra({ id: AdbSyncResponseId.Entry2 as const });
|
|
26
|
+
|
|
27
|
+
export type AdbSyncEntry2Response = typeof AdbSyncEntry2Response['TDeserializeResult'];
|
|
28
|
+
|
|
29
|
+
const LIST_V1_RESPONSE_TYPES = {
|
|
17
30
|
[AdbSyncResponseId.Entry]: AdbSyncEntryResponse,
|
|
18
31
|
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncEntryResponse.size),
|
|
19
32
|
};
|
|
20
33
|
|
|
34
|
+
const LIST_V2_RESPONSE_TYPES = {
|
|
35
|
+
[AdbSyncResponseId.Entry2]: AdbSyncEntry2Response,
|
|
36
|
+
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncEntry2Response.size),
|
|
37
|
+
};
|
|
38
|
+
|
|
21
39
|
export async function* adbSyncOpenDir(
|
|
22
40
|
stream: AdbBufferedStream,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
42
|
+
path: string,
|
|
43
|
+
v2: boolean,
|
|
44
|
+
): AsyncGenerator<AdbSyncEntry, void, void> {
|
|
45
|
+
let requestId: AdbSyncRequestId.List | AdbSyncRequestId.List2;
|
|
46
|
+
let responseType: typeof LIST_V1_RESPONSE_TYPES | typeof LIST_V2_RESPONSE_TYPES;
|
|
47
|
+
|
|
48
|
+
if (v2) {
|
|
49
|
+
requestId = AdbSyncRequestId.List2;
|
|
50
|
+
responseType = LIST_V2_RESPONSE_TYPES;
|
|
51
|
+
} else {
|
|
52
|
+
requestId = AdbSyncRequestId.List;
|
|
53
|
+
responseType = LIST_V1_RESPONSE_TYPES;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
await adbSyncWriteRequest(writer, requestId, path);
|
|
26
57
|
|
|
27
58
|
while (true) {
|
|
28
|
-
const response = await adbSyncReadResponse(stream,
|
|
59
|
+
const response = await adbSyncReadResponse(stream, responseType);
|
|
29
60
|
switch (response.id) {
|
|
30
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
|
+
}
|
|
31
78
|
yield response;
|
|
32
79
|
break;
|
|
33
80
|
case AdbSyncResponseId.Done:
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import Struct from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
-
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
2
|
+
import { AdbBufferedStream, ReadableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
4
|
+
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
5
5
|
|
|
6
6
|
export const AdbSyncDataResponse =
|
|
7
7
|
new Struct({ littleEndian: true })
|
|
8
8
|
.uint32('dataLength')
|
|
9
|
-
.
|
|
9
|
+
.uint8Array('data', { lengthField: 'dataLength' })
|
|
10
10
|
.extra({ id: AdbSyncResponseId.Data as const });
|
|
11
11
|
|
|
12
12
|
const ResponseTypes = {
|
|
@@ -14,21 +14,30 @@ const ResponseTypes = {
|
|
|
14
14
|
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncDataResponse.size),
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export function adbSyncPull(
|
|
18
18
|
stream: AdbBufferedStream,
|
|
19
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
19
20
|
path: string,
|
|
20
|
-
):
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
): ReadableStream<Uint8Array> {
|
|
22
|
+
return new ReadableStream<Uint8Array>({
|
|
23
|
+
async start() {
|
|
24
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Receive, path);
|
|
25
|
+
},
|
|
26
|
+
async pull(controller) {
|
|
27
|
+
const response = await adbSyncReadResponse(stream, ResponseTypes);
|
|
28
|
+
switch (response.id) {
|
|
29
|
+
case AdbSyncResponseId.Data:
|
|
30
|
+
controller.enqueue(response.data!);
|
|
31
|
+
break;
|
|
32
|
+
case AdbSyncResponseId.Done:
|
|
33
|
+
controller.close();
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
throw new Error('Unexpected response id');
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
|
-
}
|
|
39
|
+
}, {
|
|
40
|
+
highWaterMark: 16 * 1024,
|
|
41
|
+
size(chunk) { return chunk.byteLength; }
|
|
42
|
+
});
|
|
34
43
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import Struct from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { LinuxFileType } from './stat';
|
|
2
|
+
import { AdbBufferedStream, ChunkStream, pipeFrom, WritableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
4
|
+
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
5
|
+
import { LinuxFileType } from './stat.js';
|
|
7
6
|
|
|
8
7
|
export const AdbSyncOkResponse =
|
|
9
8
|
new Struct({ littleEndian: true })
|
|
@@ -13,34 +12,30 @@ const ResponseTypes = {
|
|
|
13
12
|
[AdbSyncResponseId.Ok]: AdbSyncOkResponse,
|
|
14
13
|
};
|
|
15
14
|
|
|
16
|
-
export const
|
|
15
|
+
export const ADB_SYNC_MAX_PACKET_SIZE = 64 * 1024;
|
|
17
16
|
|
|
18
|
-
export
|
|
17
|
+
export function adbSyncPush(
|
|
19
18
|
stream: AdbBufferedStream,
|
|
19
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
20
20
|
filename: string,
|
|
21
|
-
content: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
|
|
22
21
|
mode: number = (LinuxFileType.File << 12) | 0o666,
|
|
23
22
|
mtime: number = (Date.now() / 1000) | 0,
|
|
24
|
-
packetSize: number =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await adbSyncWriteRequest(stream, AdbSyncRequestId.Done, mtime);
|
|
45
|
-
await adbSyncReadResponse(stream, ResponseTypes);
|
|
23
|
+
packetSize: number = ADB_SYNC_MAX_PACKET_SIZE,
|
|
24
|
+
): WritableStream<Uint8Array> {
|
|
25
|
+
return pipeFrom(
|
|
26
|
+
new WritableStream<Uint8Array>({
|
|
27
|
+
async start() {
|
|
28
|
+
const pathAndMode = `${filename},${mode.toString()}`;
|
|
29
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Send, pathAndMode);
|
|
30
|
+
},
|
|
31
|
+
async write(chunk) {
|
|
32
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Data, chunk);
|
|
33
|
+
},
|
|
34
|
+
async close() {
|
|
35
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Done, mtime);
|
|
36
|
+
await adbSyncReadResponse(stream, ResponseTypes);
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
new ChunkStream(packetSize)
|
|
40
|
+
);
|
|
46
41
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import Struct from '@yume-chan/struct';
|
|
2
|
-
import type {
|
|
3
|
-
import { encodeUtf8 } from "../../utils";
|
|
2
|
+
import type { WritableStreamDefaultWriter } from "../../stream/index.js";
|
|
3
|
+
import { encodeUtf8 } from "../../utils/index.js";
|
|
4
4
|
|
|
5
5
|
export enum AdbSyncRequestId {
|
|
6
6
|
List = 'LIST',
|
|
7
|
+
List2 = 'LIS2',
|
|
7
8
|
Send = 'SEND',
|
|
8
9
|
Lstat = 'STAT',
|
|
9
10
|
Stat = 'STA2',
|
|
@@ -21,14 +22,14 @@ export const AdbSyncNumberRequest =
|
|
|
21
22
|
export const AdbSyncDataRequest =
|
|
22
23
|
new Struct({ littleEndian: true })
|
|
23
24
|
.fields(AdbSyncNumberRequest)
|
|
24
|
-
.
|
|
25
|
+
.uint8Array('data', { lengthField: 'arg' });
|
|
25
26
|
|
|
26
27
|
export async function adbSyncWriteRequest(
|
|
27
|
-
|
|
28
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
28
29
|
id: AdbSyncRequestId | string,
|
|
29
|
-
value: number | string |
|
|
30
|
+
value: number | string | Uint8Array
|
|
30
31
|
): Promise<void> {
|
|
31
|
-
let buffer:
|
|
32
|
+
let buffer: Uint8Array;
|
|
32
33
|
if (typeof value === 'number') {
|
|
33
34
|
buffer = AdbSyncNumberRequest.serialize({
|
|
34
35
|
id,
|
|
@@ -45,5 +46,5 @@ export async function adbSyncWriteRequest(
|
|
|
45
46
|
data: value,
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
|
-
await
|
|
49
|
+
await writer.write(buffer);
|
|
49
50
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import Struct, { StructAsyncDeserializeStream, StructLike, StructValueType } from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { decodeUtf8 } from "../../utils";
|
|
1
|
+
import Struct, { type StructAsyncDeserializeStream, type StructLike, type StructValueType } from '@yume-chan/struct';
|
|
2
|
+
import type { AdbBufferedStream } from '../../stream/index.js';
|
|
3
|
+
import { decodeUtf8 } from "../../utils/index.js";
|
|
4
4
|
|
|
5
5
|
export enum AdbSyncResponseId {
|
|
6
6
|
Entry = 'DENT',
|
|
7
|
+
Entry2 = 'DNT2',
|
|
7
8
|
Lstat = 'STAT',
|
|
8
9
|
Stat = 'STA2',
|
|
9
10
|
Lstat2 = 'LST2',
|
|
@@ -43,7 +44,12 @@ export const AdbSyncFailResponse =
|
|
|
43
44
|
export async function adbSyncReadResponse<T extends Record<string, StructLike<any>>>(
|
|
44
45
|
stream: AdbBufferedStream,
|
|
45
46
|
types: T,
|
|
46
|
-
|
|
47
|
+
// When `T` is a union type, `T[keyof T]` only includes their common keys.
|
|
48
|
+
// For example, let `type T = { a: string, b: string } | { a: string, c: string}`,
|
|
49
|
+
// `keyof T` is `'a'`, not `'a' | 'b' | 'c'`.
|
|
50
|
+
// However, `T extends unknown ? keyof T : never` will distribute `T`,
|
|
51
|
+
// so returns all keys.
|
|
52
|
+
): Promise<StructValueType<T extends unknown ? T[keyof T] : never>> {
|
|
47
53
|
const id = decodeUtf8(await stream.read(4));
|
|
48
54
|
|
|
49
55
|
if (id === AdbSyncResponseId.Fail) {
|
|
@@ -51,8 +57,8 @@ export async function adbSyncReadResponse<T extends Record<string, StructLike<an
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
if (types[id]) {
|
|
54
|
-
return types[id]
|
|
60
|
+
return types[id]!.deserialize(stream);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
throw new Error('
|
|
63
|
+
throw new Error(`Expected '${Object.keys(types).join(', ')}', but got '${id}'`);
|
|
58
64
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Struct, { placeholder } from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
-
import { adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
2
|
+
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
4
|
+
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
5
5
|
|
|
6
6
|
// https://github.com/python/cpython/blob/4e581d64b8aff3e2eda99b12f080c877bb78dfca/Lib/stat.py#L36
|
|
7
7
|
export enum LinuxFileType {
|
|
@@ -10,6 +10,19 @@ export enum LinuxFileType {
|
|
|
10
10
|
Link = 0o12,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface AdbSyncStat {
|
|
14
|
+
mode: number;
|
|
15
|
+
size: bigint;
|
|
16
|
+
mtime: bigint;
|
|
17
|
+
get type(): LinuxFileType;
|
|
18
|
+
get permission(): number;
|
|
19
|
+
|
|
20
|
+
uid?: number;
|
|
21
|
+
gid?: number;
|
|
22
|
+
atime?: bigint;
|
|
23
|
+
ctime?: bigint;
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
export const AdbSyncLstatResponse =
|
|
14
27
|
new Struct({ littleEndian: true })
|
|
15
28
|
.int32('mode')
|
|
@@ -32,6 +45,7 @@ export const AdbSyncLstatResponse =
|
|
|
32
45
|
export type AdbSyncLstatResponse = typeof AdbSyncLstatResponse['TDeserializeResult'];
|
|
33
46
|
|
|
34
47
|
export enum AdbSyncStatErrorCode {
|
|
48
|
+
SUCCESS = 0,
|
|
35
49
|
EACCES = 13,
|
|
36
50
|
EEXIST = 17,
|
|
37
51
|
EFAULT = 14,
|
|
@@ -80,42 +94,57 @@ export const AdbSyncStatResponse =
|
|
|
80
94
|
|
|
81
95
|
export type AdbSyncStatResponse = typeof AdbSyncStatResponse['TDeserializeResult'];
|
|
82
96
|
|
|
83
|
-
const
|
|
97
|
+
const STAT_RESPONSE_TYPES = {
|
|
84
98
|
[AdbSyncResponseId.Stat]: AdbSyncStatResponse,
|
|
85
99
|
};
|
|
86
100
|
|
|
87
|
-
const
|
|
101
|
+
const LSTAT_RESPONSE_TYPES = {
|
|
88
102
|
[AdbSyncResponseId.Lstat]: AdbSyncLstatResponse,
|
|
89
103
|
};
|
|
90
104
|
|
|
91
|
-
const
|
|
105
|
+
const LSTAT_V2_RESPONSE_TYPES = {
|
|
92
106
|
[AdbSyncResponseId.Lstat2]: AdbSyncStatResponse,
|
|
93
107
|
};
|
|
94
108
|
|
|
95
109
|
export async function adbSyncLstat(
|
|
96
110
|
stream: AdbBufferedStream,
|
|
111
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
97
112
|
path: string,
|
|
98
113
|
v2: boolean,
|
|
99
|
-
): Promise<
|
|
114
|
+
): Promise<AdbSyncStat> {
|
|
100
115
|
let requestId: AdbSyncRequestId.Lstat | AdbSyncRequestId.Lstat2;
|
|
101
|
-
let responseType: typeof
|
|
116
|
+
let responseType: typeof LSTAT_RESPONSE_TYPES | typeof LSTAT_V2_RESPONSE_TYPES;
|
|
102
117
|
|
|
103
118
|
if (v2) {
|
|
104
119
|
requestId = AdbSyncRequestId.Lstat2;
|
|
105
|
-
responseType =
|
|
120
|
+
responseType = LSTAT_V2_RESPONSE_TYPES;
|
|
106
121
|
} else {
|
|
107
122
|
requestId = AdbSyncRequestId.Lstat;
|
|
108
|
-
responseType =
|
|
123
|
+
responseType = LSTAT_RESPONSE_TYPES;
|
|
109
124
|
}
|
|
110
125
|
|
|
111
|
-
await adbSyncWriteRequest(
|
|
112
|
-
|
|
126
|
+
await adbSyncWriteRequest(writer, requestId, path);
|
|
127
|
+
const response = await adbSyncReadResponse(stream, responseType);
|
|
128
|
+
|
|
129
|
+
switch (response.id) {
|
|
130
|
+
case AdbSyncResponseId.Lstat:
|
|
131
|
+
return {
|
|
132
|
+
mode: response.mode,
|
|
133
|
+
size: BigInt(response.size),
|
|
134
|
+
mtime: BigInt(response.mtime),
|
|
135
|
+
get type() { return response.type; },
|
|
136
|
+
get permission() { return response.permission; },
|
|
137
|
+
};
|
|
138
|
+
default:
|
|
139
|
+
return response;
|
|
140
|
+
}
|
|
113
141
|
}
|
|
114
142
|
|
|
115
143
|
export async function adbSyncStat(
|
|
116
144
|
stream: AdbBufferedStream,
|
|
145
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
117
146
|
path: string,
|
|
118
147
|
): Promise<AdbSyncStatResponse> {
|
|
119
|
-
await adbSyncWriteRequest(
|
|
120
|
-
return adbSyncReadResponse(stream,
|
|
148
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Stat, path);
|
|
149
|
+
return await adbSyncReadResponse(stream, STAT_RESPONSE_TYPES);
|
|
121
150
|
}
|
|
@@ -1,37 +1,70 @@
|
|
|
1
1
|
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
-
import { Adb } from '../../adb';
|
|
3
|
-
import { AdbFeatures } from '../../features';
|
|
4
|
-
import { AdbSocket } from '../../socket';
|
|
5
|
-
import { AdbBufferedStream } from '../../stream';
|
|
6
|
-
import { AutoResetEvent } from '../../utils';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import type { Adb } from '../../adb.js';
|
|
3
|
+
import { AdbFeatures } from '../../features.js';
|
|
4
|
+
import type { AdbSocket } from '../../socket/index.js';
|
|
5
|
+
import { AdbBufferedStream, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
6
|
+
import { AutoResetEvent } from '../../utils/index.js';
|
|
7
|
+
import { escapeArg } from "../index.js";
|
|
8
|
+
import { adbSyncOpenDir, type AdbSyncEntry } from './list.js';
|
|
9
|
+
import { adbSyncPull } from './pull.js';
|
|
10
|
+
import { adbSyncPush } from './push.js';
|
|
11
|
+
import { adbSyncLstat, adbSyncStat } from './stat.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A simplified `dirname` function that only handles absolute unix paths.
|
|
15
|
+
* @param path an absolute unix path
|
|
16
|
+
* @returns the directory name of the input path
|
|
17
|
+
*/
|
|
18
|
+
export function dirname(path: string): string {
|
|
19
|
+
const end = path.lastIndexOf('/');
|
|
20
|
+
if (end === -1) {
|
|
21
|
+
throw new Error(`Invalid path`);
|
|
22
|
+
}
|
|
23
|
+
if (end === 0) {
|
|
24
|
+
return '/';
|
|
25
|
+
}
|
|
26
|
+
return path.substring(0, end);
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
export class AdbSync extends AutoDisposable {
|
|
13
30
|
protected adb: Adb;
|
|
14
31
|
|
|
15
32
|
protected stream: AdbBufferedStream;
|
|
16
33
|
|
|
34
|
+
protected writer: WritableStreamDefaultWriter<Uint8Array>;
|
|
35
|
+
|
|
17
36
|
protected sendLock = this.addDisposable(new AutoResetEvent());
|
|
18
37
|
|
|
19
38
|
public get supportsStat(): boolean {
|
|
20
39
|
return this.adb.features!.includes(AdbFeatures.StatV2);
|
|
21
40
|
}
|
|
22
41
|
|
|
42
|
+
public get supportsList2(): boolean {
|
|
43
|
+
return this.adb.features!.includes(AdbFeatures.ListV2);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public get fixedPushMkdir(): boolean {
|
|
47
|
+
return this.adb.features!.includes(AdbFeatures.FixedPushMkdir);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public get needPushMkdirWorkaround(): boolean {
|
|
51
|
+
// https://android.googlesource.com/platform/packages/modules/adb/+/91768a57b7138166e0a3d11f79cd55909dda7014/client/file_sync_client.cpp#1361
|
|
52
|
+
return this.adb.features!.includes(AdbFeatures.ShellV2) && !this.fixedPushMkdir;
|
|
53
|
+
}
|
|
54
|
+
|
|
23
55
|
public constructor(adb: Adb, socket: AdbSocket) {
|
|
24
56
|
super();
|
|
25
57
|
|
|
26
58
|
this.adb = adb;
|
|
27
59
|
this.stream = new AdbBufferedStream(socket);
|
|
60
|
+
this.writer = socket.writable.getWriter();
|
|
28
61
|
}
|
|
29
62
|
|
|
30
63
|
public async lstat(path: string) {
|
|
31
64
|
await this.sendLock.wait();
|
|
32
65
|
|
|
33
66
|
try {
|
|
34
|
-
return adbSyncLstat(this.stream, path, this.supportsStat);
|
|
67
|
+
return adbSyncLstat(this.stream, this.writer, path, this.supportsStat);
|
|
35
68
|
} finally {
|
|
36
69
|
this.sendLock.notify();
|
|
37
70
|
}
|
|
@@ -45,7 +78,7 @@ export class AdbSync extends AutoDisposable {
|
|
|
45
78
|
await this.sendLock.wait();
|
|
46
79
|
|
|
47
80
|
try {
|
|
48
|
-
return adbSyncStat(this.stream, path);
|
|
81
|
+
return adbSyncStat(this.stream, this.writer, path);
|
|
49
82
|
} finally {
|
|
50
83
|
this.sendLock.notify();
|
|
51
84
|
}
|
|
@@ -62,52 +95,87 @@ export class AdbSync extends AutoDisposable {
|
|
|
62
95
|
|
|
63
96
|
public async *opendir(
|
|
64
97
|
path: string
|
|
65
|
-
): AsyncGenerator<
|
|
98
|
+
): AsyncGenerator<AdbSyncEntry, void, void> {
|
|
66
99
|
await this.sendLock.wait();
|
|
67
100
|
|
|
68
101
|
try {
|
|
69
|
-
yield* adbSyncOpenDir(this.stream, path);
|
|
102
|
+
yield* adbSyncOpenDir(this.stream, this.writer, path, this.supportsList2);
|
|
70
103
|
} finally {
|
|
71
104
|
this.sendLock.notify();
|
|
72
105
|
}
|
|
73
106
|
}
|
|
74
107
|
|
|
75
108
|
public async readdir(path: string) {
|
|
76
|
-
const results:
|
|
109
|
+
const results: AdbSyncEntry[] = [];
|
|
77
110
|
for await (const entry of this.opendir(path)) {
|
|
78
111
|
results.push(entry);
|
|
79
112
|
}
|
|
80
113
|
return results;
|
|
81
114
|
}
|
|
82
115
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Read the content of a file on device.
|
|
118
|
+
*
|
|
119
|
+
* @param filename The full path of the file on device to read.
|
|
120
|
+
* @returns A `ReadableStream` that reads from the file.
|
|
121
|
+
*/
|
|
122
|
+
public read(filename: string): ReadableStream<Uint8Array> {
|
|
123
|
+
return new WrapReadableStream({
|
|
124
|
+
start: async () => {
|
|
125
|
+
await this.sendLock.wait();
|
|
126
|
+
return adbSyncPull(this.stream, this.writer, filename);
|
|
127
|
+
},
|
|
128
|
+
close: async () => {
|
|
129
|
+
this.sendLock.notify();
|
|
130
|
+
},
|
|
131
|
+
});
|
|
91
132
|
}
|
|
92
133
|
|
|
93
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Write (or overwrite) a file on device.
|
|
136
|
+
*
|
|
137
|
+
* @param filename The full path of the file on device to write.
|
|
138
|
+
* @param mode The unix permissions of the file.
|
|
139
|
+
* @param mtime The modified time of the file.
|
|
140
|
+
* @returns A `WritableStream` that writes to the file.
|
|
141
|
+
*/
|
|
142
|
+
public write(
|
|
94
143
|
filename: string,
|
|
95
|
-
content: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
|
|
96
144
|
mode?: number,
|
|
97
145
|
mtime?: number,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
146
|
+
): WritableStream<Uint8Array> {
|
|
147
|
+
return new WrapWritableStream({
|
|
148
|
+
start: async () => {
|
|
149
|
+
await this.sendLock.wait();
|
|
150
|
+
|
|
151
|
+
if (this.needPushMkdirWorkaround) {
|
|
152
|
+
// It may fail if the path is already existed.
|
|
153
|
+
// Ignore the result.
|
|
154
|
+
// TODO: sync: test this
|
|
155
|
+
await this.adb.subprocess.spawnAndWait([
|
|
156
|
+
'mkdir',
|
|
157
|
+
'-p',
|
|
158
|
+
escapeArg(dirname(filename)),
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return adbSyncPush(
|
|
163
|
+
this.stream,
|
|
164
|
+
this.writer,
|
|
165
|
+
filename,
|
|
166
|
+
mode,
|
|
167
|
+
mtime,
|
|
168
|
+
);
|
|
169
|
+
},
|
|
170
|
+
close: async () => {
|
|
171
|
+
this.sendLock.notify();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
107
174
|
}
|
|
108
175
|
|
|
109
|
-
public override dispose() {
|
|
176
|
+
public override async dispose() {
|
|
110
177
|
super.dispose();
|
|
111
178
|
this.stream.close();
|
|
179
|
+
await this.writer.close();
|
|
112
180
|
}
|
|
113
181
|
}
|
package/src/commands/tcpip.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdbCommandBase } from './base';
|
|
1
|
+
import { AdbCommandBase } from './base.js';
|
|
2
2
|
|
|
3
3
|
export class AdbTcpIpCommand extends AdbCommandBase {
|
|
4
4
|
public async setPort(port: number): Promise<void> {
|
|
@@ -6,14 +6,14 @@ export class AdbTcpIpCommand extends AdbCommandBase {
|
|
|
6
6
|
throw new Error(`Invalid port ${port}`);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const output = await this.adb.
|
|
9
|
+
const output = await this.adb.createSocketAndWait(`tcpip:${port}`);
|
|
10
10
|
if (output !== `restarting in TCP mode port: ${port}\n`) {
|
|
11
11
|
throw new Error('Invalid response');
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
public async disable(): Promise<void> {
|
|
16
|
-
const output = await this.adb.
|
|
16
|
+
const output = await this.adb.createSocketAndWait('usb:');
|
|
17
17
|
if (output !== 'restarting in USB mode\n') {
|
|
18
18
|
throw new Error('Invalid response');
|
|
19
19
|
}
|