@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,64 +1,68 @@
|
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
import type { BufferedReadableStream } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct, { StructValueType, type StructLike } from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import { decodeUtf8 } from '../../utils/index.js';
|
|
5
|
+
|
|
6
|
+
export enum AdbSyncResponseId {
|
|
7
|
+
Entry = 'DENT',
|
|
8
|
+
Entry2 = 'DNT2',
|
|
9
|
+
Lstat = 'STAT',
|
|
10
|
+
Stat = 'STA2',
|
|
11
|
+
Lstat2 = 'LST2',
|
|
12
|
+
Done = 'DONE',
|
|
13
|
+
Data = 'DATA',
|
|
14
|
+
Ok = 'OKAY',
|
|
15
|
+
Fail = 'FAIL',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const AdbSyncFailResponse =
|
|
19
|
+
new Struct({ littleEndian: true })
|
|
20
|
+
.uint32('messageLength')
|
|
21
|
+
.string('message', { lengthField: 'messageLength' })
|
|
22
|
+
.postDeserialize(object => {
|
|
23
|
+
throw new Error(object.message);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export async function adbSyncReadResponse<T>(
|
|
27
|
+
stream: BufferedReadableStream,
|
|
28
|
+
id: AdbSyncResponseId,
|
|
29
|
+
type: StructLike<T>,
|
|
30
|
+
): Promise<T> {
|
|
31
|
+
const actualId = decodeUtf8(await stream.read(4));
|
|
32
|
+
switch (actualId) {
|
|
33
|
+
case AdbSyncResponseId.Fail:
|
|
34
|
+
await AdbSyncFailResponse.deserialize(stream);
|
|
35
|
+
throw new Error('Unreachable');
|
|
36
|
+
case id:
|
|
37
|
+
return await type.deserialize(stream);
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Expected '${id}', but got '${actualId}'`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function* adbSyncReadResponses<T extends Struct<any, any, any, any>>(
|
|
44
|
+
stream: BufferedReadableStream,
|
|
45
|
+
id: AdbSyncResponseId,
|
|
46
|
+
type: T,
|
|
47
|
+
): AsyncGenerator<StructValueType<T>, void, void> {
|
|
48
|
+
while (true) {
|
|
49
|
+
const actualId = decodeUtf8(await stream.read(4));
|
|
50
|
+
switch (actualId) {
|
|
51
|
+
case AdbSyncResponseId.Fail:
|
|
52
|
+
await AdbSyncFailResponse.deserialize(stream);
|
|
53
|
+
throw new Error('Unreachable');
|
|
54
|
+
case AdbSyncResponseId.Done:
|
|
55
|
+
// `DONE` responses' size are always same as the request's normal response.
|
|
56
|
+
//
|
|
57
|
+
// For example, `DONE` responses for `LIST` requests are 16 bytes (same as `DENT` responses),
|
|
58
|
+
// but `DONE` responses for `STAT` requests are 12 bytes (same as `STAT` responses).
|
|
59
|
+
await stream.read(type.size);
|
|
60
|
+
return;
|
|
61
|
+
case id:
|
|
62
|
+
yield await type.deserialize(stream);
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
throw new Error(`Expected '${id}' or '${AdbSyncResponseId.Done}', but got '${actualId}'`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,150 +1,129 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
get
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.int32('
|
|
30
|
-
.int32('
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
get
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
object.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.
|
|
76
|
-
.
|
|
77
|
-
.
|
|
78
|
-
.uint32('
|
|
79
|
-
.uint32('
|
|
80
|
-
.
|
|
81
|
-
.
|
|
82
|
-
.uint64('
|
|
83
|
-
.uint64('
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function adbSyncStat(
|
|
144
|
-
stream: AdbBufferedStream,
|
|
145
|
-
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
146
|
-
path: string,
|
|
147
|
-
): Promise<AdbSyncStatResponse> {
|
|
148
|
-
await adbSyncWriteRequest(writer, AdbSyncRequestId.Stat, path);
|
|
149
|
-
return await adbSyncReadResponse(stream, STAT_RESPONSE_TYPES);
|
|
150
|
-
}
|
|
1
|
+
import type { BufferedReadableStream, WritableStreamDefaultWriter } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct, { placeholder } from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
5
|
+
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
6
|
+
|
|
7
|
+
// https://github.com/python/cpython/blob/4e581d64b8aff3e2eda99b12f080c877bb78dfca/Lib/stat.py#L36
|
|
8
|
+
export enum LinuxFileType {
|
|
9
|
+
Directory = 0o04,
|
|
10
|
+
File = 0o10,
|
|
11
|
+
Link = 0o12,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AdbSyncStat {
|
|
15
|
+
mode: number;
|
|
16
|
+
size: bigint;
|
|
17
|
+
mtime: bigint;
|
|
18
|
+
get type(): LinuxFileType;
|
|
19
|
+
get permission(): number;
|
|
20
|
+
|
|
21
|
+
uid?: number;
|
|
22
|
+
gid?: number;
|
|
23
|
+
atime?: bigint;
|
|
24
|
+
ctime?: bigint;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const AdbSyncLstatResponse =
|
|
28
|
+
new Struct({ littleEndian: true })
|
|
29
|
+
.int32('mode')
|
|
30
|
+
.int32('size')
|
|
31
|
+
.int32('mtime')
|
|
32
|
+
.extra({
|
|
33
|
+
id: AdbSyncResponseId.Lstat as const,
|
|
34
|
+
get type() { return this.mode >> 12 as LinuxFileType; },
|
|
35
|
+
get permission() { return this.mode & 0b00001111_11111111; },
|
|
36
|
+
})
|
|
37
|
+
.postDeserialize((object) => {
|
|
38
|
+
if (
|
|
39
|
+
object.mode === 0 &&
|
|
40
|
+
object.size === 0 &&
|
|
41
|
+
object.mtime === 0
|
|
42
|
+
) {
|
|
43
|
+
throw new Error('lstat failed');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export type AdbSyncLstatResponse = typeof AdbSyncLstatResponse['TDeserializeResult'];
|
|
48
|
+
|
|
49
|
+
export enum AdbSyncStatErrorCode {
|
|
50
|
+
SUCCESS = 0,
|
|
51
|
+
EACCES = 13,
|
|
52
|
+
EEXIST = 17,
|
|
53
|
+
EFAULT = 14,
|
|
54
|
+
EFBIG = 27,
|
|
55
|
+
EINTR = 4,
|
|
56
|
+
EINVAL = 22,
|
|
57
|
+
EIO = 5,
|
|
58
|
+
EISDIR = 21,
|
|
59
|
+
ELOOP = 40,
|
|
60
|
+
EMFILE = 24,
|
|
61
|
+
ENAMETOOLONG = 36,
|
|
62
|
+
ENFILE = 23,
|
|
63
|
+
ENOENT = 2,
|
|
64
|
+
ENOMEM = 12,
|
|
65
|
+
ENOSPC = 28,
|
|
66
|
+
ENOTDIR = 20,
|
|
67
|
+
EOVERFLOW = 75,
|
|
68
|
+
EPERM = 1,
|
|
69
|
+
EROFS = 30,
|
|
70
|
+
ETXTBSY = 26,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const AdbSyncStatResponse =
|
|
74
|
+
new Struct({ littleEndian: true })
|
|
75
|
+
.uint32('error', placeholder<AdbSyncStatErrorCode>())
|
|
76
|
+
.uint64('dev')
|
|
77
|
+
.uint64('ino')
|
|
78
|
+
.uint32('mode')
|
|
79
|
+
.uint32('nlink')
|
|
80
|
+
.uint32('uid')
|
|
81
|
+
.uint32('gid')
|
|
82
|
+
.uint64('size')
|
|
83
|
+
.uint64('atime')
|
|
84
|
+
.uint64('mtime')
|
|
85
|
+
.uint64('ctime')
|
|
86
|
+
.extra({
|
|
87
|
+
id: AdbSyncResponseId.Stat as const,
|
|
88
|
+
get type() { return this.mode >> 12 as LinuxFileType; },
|
|
89
|
+
get permission() { return this.mode & 0b00001111_11111111; },
|
|
90
|
+
})
|
|
91
|
+
.postDeserialize((object) => {
|
|
92
|
+
if (object.error) {
|
|
93
|
+
throw new Error(AdbSyncStatErrorCode[object.error]);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export type AdbSyncStatResponse = typeof AdbSyncStatResponse['TDeserializeResult'];
|
|
98
|
+
|
|
99
|
+
export async function adbSyncLstat(
|
|
100
|
+
stream: BufferedReadableStream,
|
|
101
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
102
|
+
path: string,
|
|
103
|
+
v2: boolean,
|
|
104
|
+
): Promise<AdbSyncStat> {
|
|
105
|
+
if (v2) {
|
|
106
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Lstat2, path);
|
|
107
|
+
return await adbSyncReadResponse(stream, AdbSyncResponseId.Lstat2, AdbSyncStatResponse);
|
|
108
|
+
} else {
|
|
109
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Lstat, path);
|
|
110
|
+
const response = await adbSyncReadResponse(stream, AdbSyncResponseId.Lstat, AdbSyncLstatResponse);
|
|
111
|
+
return {
|
|
112
|
+
mode: response.mode,
|
|
113
|
+
// Convert to `BigInt` to make it compatible with `AdbSyncStatResponse`
|
|
114
|
+
size: BigInt(response.size),
|
|
115
|
+
mtime: BigInt(response.mtime),
|
|
116
|
+
get type() { return response.type; },
|
|
117
|
+
get permission() { return response.permission; },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function adbSyncStat(
|
|
123
|
+
stream: BufferedReadableStream,
|
|
124
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
125
|
+
path: string,
|
|
126
|
+
): Promise<AdbSyncStatResponse> {
|
|
127
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Stat, path);
|
|
128
|
+
return await adbSyncReadResponse(stream, AdbSyncResponseId.Stat, AdbSyncStatResponse);
|
|
129
|
+
}
|