@yume-chan/adb 3.0.0-beta.1 → 3.0.0-beta.3
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/esm/adb.d.ts +7 -2
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +2 -2
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts.map +1 -1
- package/esm/banner.js.map +1 -1
- package/esm/daemon/crypto.d.ts.map +1 -1
- package/esm/daemon/crypto.js +53 -18
- package/esm/daemon/crypto.js.map +1 -1
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +2 -1
- package/esm/server/client.js.map +1 -1
- package/esm/server/transport.d.ts +1 -1
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +2 -2
- package/esm/server/transport.js.map +1 -1
- package/esm/service/subprocess/shell/spawner.d.ts.map +1 -1
- package/esm/service/subprocess/shell/spawner.js.map +1 -1
- package/esm/service/sync/compression/adapters.d.ts +16 -0
- package/esm/service/sync/compression/adapters.d.ts.map +1 -0
- package/esm/service/sync/compression/adapters.js +84 -0
- package/esm/service/sync/compression/adapters.js.map +1 -0
- package/esm/service/sync/compression/format-ns.d.ts.map +1 -1
- package/esm/service/sync/compression/format-ns.js +1 -0
- package/esm/service/sync/compression/format-ns.js.map +1 -1
- package/esm/service/sync/compression/format.d.ts +1 -0
- package/esm/service/sync/compression/format.d.ts.map +1 -1
- package/esm/service/sync/compression/format.js +1 -0
- package/esm/service/sync/compression/format.js.map +1 -1
- package/esm/service/sync/compression/index.d.ts +1 -1
- package/esm/service/sync/compression/index.d.ts.map +1 -1
- package/esm/service/sync/compression/index.js +1 -1
- package/esm/service/sync/compression/index.js.map +1 -1
- package/esm/service/sync/compression/mode.d.ts +6 -0
- package/esm/service/sync/compression/mode.d.ts.map +1 -0
- package/esm/service/sync/compression/mode.js +5 -0
- package/esm/service/sync/compression/mode.js.map +1 -0
- package/esm/service/sync/compression/native.d.ts +8 -0
- package/esm/service/sync/compression/native.d.ts.map +1 -0
- package/esm/service/sync/compression/native.js +53 -0
- package/esm/service/sync/compression/native.js.map +1 -0
- package/esm/service/sync/id/request.d.ts +1 -0
- package/esm/service/sync/id/request.d.ts.map +1 -1
- package/esm/service/sync/id/request.js +1 -0
- package/esm/service/sync/id/request.js.map +1 -1
- package/esm/service/sync/request/flag.d.ts +9 -0
- package/esm/service/sync/request/flag.d.ts.map +1 -0
- package/esm/service/sync/request/flag.js +8 -0
- package/esm/service/sync/request/flag.js.map +1 -0
- package/esm/service/sync/request/pull.d.ts +25 -2
- package/esm/service/sync/request/pull.d.ts.map +1 -1
- package/esm/service/sync/request/pull.js +76 -16
- package/esm/service/sync/request/pull.js.map +1 -1
- package/esm/service/sync/request/push.d.ts +36 -14
- package/esm/service/sync/request/push.d.ts.map +1 -1
- package/esm/service/sync/request/push.js +162 -60
- package/esm/service/sync/request/push.js.map +1 -1
- package/esm/service/sync/service.d.ts +32 -16
- package/esm/service/sync/service.d.ts.map +1 -1
- package/esm/service/sync/service.js +58 -13
- package/esm/service/sync/service.js.map +1 -1
- package/esm/service/sync/socket-pool.d.ts +1 -0
- package/esm/service/sync/socket-pool.d.ts.map +1 -1
- package/esm/service/sync/socket-pool.js +45 -9
- package/esm/service/sync/socket-pool.js.map +1 -1
- package/esm/service/sync/socket.d.ts +4 -0
- package/esm/service/sync/socket.d.ts.map +1 -1
- package/esm/service/sync/socket.js +16 -0
- package/esm/service/sync/socket.js.map +1 -1
- package/esm/utils/ref.d.ts +3 -5
- package/esm/utils/ref.d.ts.map +1 -1
- package/esm/utils/ref.js +12 -6
- package/esm/utils/ref.js.map +1 -1
- package/package.json +6 -6
- package/src/adb.ts +15 -3
- package/src/banner.ts +1 -2
- package/src/daemon/crypto.ts +65 -23
- package/src/server/client.ts +5 -1
- package/src/server/transport.ts +5 -1
- package/src/service/subprocess/shell/spawner.ts +3 -1
- package/src/service/sync/compression/adapters.ts +137 -0
- package/src/service/sync/compression/format-ns.ts +2 -0
- package/src/service/sync/compression/format.ts +5 -0
- package/src/service/sync/compression/index.ts +1 -1
- package/src/service/sync/compression/mode.ts +6 -0
- package/src/service/sync/compression/native.ts +73 -0
- package/src/service/sync/id/request.ts +1 -0
- package/src/service/sync/request/flag.ts +9 -0
- package/src/service/sync/request/pull.ts +135 -27
- package/src/service/sync/request/push.ts +235 -88
- package/src/service/sync/service.ts +87 -27
- package/src/service/sync/socket-pool.ts +50 -9
- package/src/service/sync/socket.ts +23 -1
- package/src/utils/ref.ts +17 -7
- package/esm/service/sync/compression/compression.d.ts +0 -17
- package/esm/service/sync/compression/compression.d.ts.map +0 -1
- package/esm/service/sync/compression/compression.js +0 -92
- package/esm/service/sync/compression/compression.js.map +0 -1
- package/src/service/sync/compression/compression.ts +0 -126
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CompressionStream, DecompressionStream, TransformStream, } from "@yume-chan/stream-extra";
|
|
2
|
+
import { NOOP } from "../../../utils/no-op.js";
|
|
3
|
+
import { Format } from "./format.js";
|
|
4
|
+
import { Mode } from "./mode.js";
|
|
5
|
+
export const FormatMap = {
|
|
6
|
+
[Format.None]: "",
|
|
7
|
+
// https://github.com/whatwg/compression/issues/54
|
|
8
|
+
[Format.Zstd]: "zstd",
|
|
9
|
+
// placeholder
|
|
10
|
+
[Format.Lz4]: "lz4",
|
|
11
|
+
// https://github.com/whatwg/compression/pull/80
|
|
12
|
+
[Format.Brotli]: "brotli",
|
|
13
|
+
};
|
|
14
|
+
const CompressionFormatCache = new Map();
|
|
15
|
+
const DecompressionFormatCache = new Map();
|
|
16
|
+
export function hasNativeSupport(format, mode) {
|
|
17
|
+
if (format === Format.None) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const Cache = mode === Mode.Compress
|
|
21
|
+
? CompressionFormatCache
|
|
22
|
+
: DecompressionFormatCache;
|
|
23
|
+
if (Cache.has(format)) {
|
|
24
|
+
return Cache.get(format);
|
|
25
|
+
}
|
|
26
|
+
const Stream = mode === Mode.Compress ? CompressionStream : DecompressionStream;
|
|
27
|
+
if (!Stream) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const stream = new Stream(FormatMap[format]);
|
|
32
|
+
void stream.writable.abort().catch(NOOP);
|
|
33
|
+
Cache.set(format, true);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
Cache.set(format, false);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function createNativeCompressionStream(format) {
|
|
42
|
+
if (format === Format.None) {
|
|
43
|
+
return new TransformStream();
|
|
44
|
+
}
|
|
45
|
+
return new CompressionStream(FormatMap[format]);
|
|
46
|
+
}
|
|
47
|
+
export function createNativeDecompressionStream(format) {
|
|
48
|
+
if (format === Format.None) {
|
|
49
|
+
return new TransformStream();
|
|
50
|
+
}
|
|
51
|
+
return new DecompressionStream(FormatMap[format]);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../../src/service/sync/compression/native.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GAClB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,SAAS,GAA2B;IAC7C,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE;IACjB,kDAAkD;IAClD,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM;IACrB,cAAc;IACd,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK;IACnB,gDAAgD;IAChD,CAAC,MAAM,CAAC,MAAM,CAAC,E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C;IAED,OAAO,IAAI,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC3C,MAAc;IAEd,IAAI,MAAM,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,eAAe,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/id/request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAI/D,eAAO,MAAM,IAAI,QAAmB,CAAC;AACrC,eAAO,MAAM,MAAM,QAAmB,CAAC;AAEvC,eAAO,MAAM,IAAI,QAAmB,CAAC;AACrC,eAAO,MAAM,MAAM,QAAmB,CAAC;AACvC,eAAO,MAAM,OAAO,QAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/id/request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAI/D,eAAO,MAAM,IAAI,QAAmB,CAAC;AACrC,eAAO,MAAM,MAAM,QAAmB,CAAC;AAEvC,eAAO,MAAM,IAAI,QAAmB,CAAC;AACrC,eAAO,MAAM,MAAM,QAAmB,CAAC;AACvC,eAAO,MAAM,OAAO,QAAmB,CAAC;AACxC,eAAO,MAAM,SAAS,QAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../src/service/sync/id/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE/D,+JAA+J;AAE/J,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../src/service/sync/id/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE/D,+JAA+J;AAE/J,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flag.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/request/flag.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;CAMX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flag.js","sourceRoot":"","sources":["../../../../src/service/sync/request/flag.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,UAAU;CACZ,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
2
2
|
import type { StructValue } from "@yume-chan/struct";
|
|
3
|
+
import { Compression } from "../index-ns.js";
|
|
3
4
|
import type { SocketPool } from "../socket-pool.js";
|
|
4
5
|
export declare const DataResponse: import("@yume-chan/struct").Struct<{
|
|
5
6
|
data: import("@yume-chan/struct").Field<Uint8Array<ArrayBufferLike>, string, never, Uint8Array<ArrayBufferLike>>;
|
|
@@ -7,6 +8,28 @@ export declare const DataResponse: import("@yume-chan/struct").Struct<{
|
|
|
7
8
|
data: import("@yume-chan/struct").Field<Uint8Array<ArrayBufferLike>, string, never, Uint8Array<ArrayBufferLike>>;
|
|
8
9
|
}>>;
|
|
9
10
|
export type DataResponse = StructValue<typeof DataResponse>;
|
|
10
|
-
export
|
|
11
|
-
|
|
11
|
+
export interface ReceiveSession {
|
|
12
|
+
/**
|
|
13
|
+
* The readable stream to read the file content from.
|
|
14
|
+
*/
|
|
15
|
+
readable: ReadableStream<Uint8Array>;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the number of bytes read from {@link readable}.
|
|
18
|
+
*/
|
|
19
|
+
bytesRead: number;
|
|
20
|
+
/**
|
|
21
|
+
* When using Pull v2, gets the compression format used (might be `None`).
|
|
22
|
+
*
|
|
23
|
+
* When using Pull v1, this will always be `undefined`.
|
|
24
|
+
*/
|
|
25
|
+
compression?: Compression.Format | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* When using Pull v2, gets the size of the compressed data received from the device.
|
|
28
|
+
* Might be same as {@link bytesRead} if no compression was applied.
|
|
29
|
+
*/
|
|
30
|
+
bytesCompressed: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function receiveV1(pool: SocketPool, path: string): ReceiveSession;
|
|
33
|
+
export declare function receiveV2(pool: SocketPool, path: string, compression?: Compression.Format): ReceiveSession;
|
|
34
|
+
export declare function receive(version: 1 | 2, pool: SocketPool, path: string, compression?: Compression.Format): ReceiveSession;
|
|
12
35
|
//# sourceMappingURL=pull.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/request/pull.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/request/pull.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,eAAO,MAAM,YAAY;;;;GAGxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,YAAY,CAAC,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACrC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC;IAC7C;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,CAwBxE;AAED,wBAAgB,SAAS,CACrB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,GACjC,cAAc,CAoEhB;AAED,wBAAgB,OAAO,CACnB,OAAO,EAAE,CAAC,GAAG,CAAC,EACd,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,kBAWnC"}
|
|
@@ -1,28 +1,88 @@
|
|
|
1
|
-
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
1
|
+
import { InspectStream, ReadableStream } from "@yume-chan/stream-extra";
|
|
2
2
|
import { buffer, struct, u32 } from "@yume-chan/struct";
|
|
3
3
|
import { RequestId, ResponseId } from "../id/index.js";
|
|
4
|
+
import { Compression } from "../index-ns.js";
|
|
4
5
|
import { Error as AdbSyncError } from "../socket.js";
|
|
6
|
+
import { SyncFlag } from "./flag.js";
|
|
5
7
|
export const DataResponse = struct({ data: buffer(u32) }, { littleEndian: true });
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export function receiveV1(pool, path) {
|
|
9
|
+
let bytesReceived = 0;
|
|
10
|
+
return {
|
|
11
|
+
readable: ReadableStream.from(pool.withSocketGenerator(async function* (socket) {
|
|
12
|
+
await socket.writeRequest(RequestId.Receive, path);
|
|
13
|
+
for await (const packet of socket.readResponses(ResponseId.Data, DataResponse)) {
|
|
14
|
+
bytesReceived += packet.data.length;
|
|
15
|
+
yield packet.data;
|
|
16
|
+
}
|
|
17
|
+
})),
|
|
18
|
+
get bytesRead() {
|
|
19
|
+
return bytesReceived;
|
|
20
|
+
},
|
|
21
|
+
compression: undefined,
|
|
22
|
+
get bytesCompressed() {
|
|
23
|
+
return bytesReceived;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function receiveV2(pool, path, compression) {
|
|
28
|
+
let flags = SyncFlag.None;
|
|
29
|
+
let decompressStream;
|
|
30
|
+
switch (compression) {
|
|
31
|
+
case Compression.Format.Brotli:
|
|
32
|
+
flags |= SyncFlag.Brotli;
|
|
33
|
+
decompressStream = Compression.createDecompressionStream(Compression.Format.Brotli);
|
|
34
|
+
break;
|
|
35
|
+
case Compression.Format.Lz4:
|
|
36
|
+
flags |= SyncFlag.Lz4;
|
|
37
|
+
decompressStream = Compression.createDecompressionStream(Compression.Format.Lz4);
|
|
38
|
+
break;
|
|
39
|
+
case Compression.Format.Zstd:
|
|
40
|
+
flags |= SyncFlag.Zstd;
|
|
41
|
+
decompressStream = Compression.createDecompressionStream(Compression.Format.Zstd);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
let bytesReceived = 0;
|
|
45
|
+
const raw = ReadableStream.from(pool.withSocketGenerator(async function* (socket) {
|
|
46
|
+
await socket.writeRequest(RequestId.ReceiveV2, path);
|
|
47
|
+
await socket.writeRequest(RequestId.ReceiveV2, flags);
|
|
12
48
|
for await (const packet of socket.readResponses(ResponseId.Data, DataResponse)) {
|
|
49
|
+
bytesReceived += packet.data.length;
|
|
13
50
|
yield packet.data;
|
|
14
51
|
}
|
|
15
|
-
|
|
52
|
+
}));
|
|
53
|
+
if (decompressStream) {
|
|
54
|
+
let bytesRead = 0;
|
|
55
|
+
return {
|
|
56
|
+
readable: raw.pipeThrough(decompressStream).pipeThrough(new InspectStream((chunk) => {
|
|
57
|
+
bytesRead += chunk.length;
|
|
58
|
+
})),
|
|
59
|
+
get bytesRead() {
|
|
60
|
+
return bytesRead;
|
|
61
|
+
},
|
|
62
|
+
compression,
|
|
63
|
+
get bytesCompressed() {
|
|
64
|
+
return bytesReceived;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
16
67
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
68
|
+
return {
|
|
69
|
+
readable: raw,
|
|
70
|
+
get bytesRead() {
|
|
71
|
+
return bytesReceived;
|
|
72
|
+
},
|
|
73
|
+
compression: Compression.Format.None,
|
|
74
|
+
get bytesCompressed() {
|
|
75
|
+
return bytesReceived;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function receive(version, pool, path, compression) {
|
|
80
|
+
if (version === 2) {
|
|
81
|
+
return receiveV2(pool, path, compression);
|
|
20
82
|
}
|
|
21
|
-
|
|
22
|
-
|
|
83
|
+
if (compression !== undefined && compression !== Compression.Format.None) {
|
|
84
|
+
throw new AdbSyncError("compression is not supported in v1");
|
|
23
85
|
}
|
|
24
|
-
|
|
25
|
-
export function stream(pool, path) {
|
|
26
|
-
return ReadableStream.from(generator(pool, path));
|
|
86
|
+
return receiveV1(pool, path);
|
|
27
87
|
}
|
|
28
88
|
//# sourceMappingURL=pull.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull.js","sourceRoot":"","sources":["../../../../src/service/sync/request/pull.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pull.js","sourceRoot":"","sources":["../../../../src/service/sync/request/pull.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAExE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAC9B,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,C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T,OAAO,aAAa,CAAC;QACzB,CAAC;QACD,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI;QACpC,IAAI,eAAe;YACf,OAAO,aAAa,CAAC;QACzB,CAAC;KACJ,CAAC;AACN,CAAC;AAED,MAAM,UAAU,OAAO,CACnB,OAAc,EACd,IAAgB,EAChB,IAAY,EACZ,WAAgC;IAEhC,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACvE,MAAM,IAAI,YAAY,CAAC,oCAAoC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WritableStream } from "@yume-chan/stream-extra";
|
|
2
2
|
import { MaybeConsumable } from "@yume-chan/stream-extra";
|
|
3
3
|
import { LinuxFileType } from "../android.js";
|
|
4
4
|
import { Compression } from "../compression/index.js";
|
|
@@ -9,24 +9,36 @@ export declare const OkResponse: import("@yume-chan/struct").Struct<{
|
|
|
9
9
|
}, undefined, import("@yume-chan/struct").FieldsValue<{
|
|
10
10
|
unused: import("@yume-chan/struct").NumberField<number>;
|
|
11
11
|
}>>;
|
|
12
|
+
export interface SendSession {
|
|
13
|
+
/**
|
|
14
|
+
* The writable stream to write the file content into.
|
|
15
|
+
*/
|
|
16
|
+
writable: WritableStream<MaybeConsumable<Uint8Array>>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the number of bytes written into {@link writable}.
|
|
19
|
+
*/
|
|
20
|
+
bytesWritten: number;
|
|
21
|
+
/**
|
|
22
|
+
* When using Send v2, gets the compression format used (might be `None`).
|
|
23
|
+
*
|
|
24
|
+
* When using Send v1, this will always be `undefined`.
|
|
25
|
+
*/
|
|
26
|
+
compression?: Compression.Format | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* When using Send v2, gets the size of the compressed data sent to the device.
|
|
29
|
+
* Might be same as {@link bytesWritten} if no compression was applied.
|
|
30
|
+
*/
|
|
31
|
+
bytesCompressed: number;
|
|
32
|
+
}
|
|
12
33
|
export interface SendV1Options {
|
|
13
34
|
pool: SocketPool;
|
|
14
|
-
|
|
15
|
-
file: ReadableStream<MaybeConsumable<Uint8Array>>;
|
|
35
|
+
path: string;
|
|
16
36
|
type?: LinuxFileType | undefined;
|
|
17
37
|
permission?: number | undefined;
|
|
18
38
|
mtime?: number | undefined;
|
|
19
39
|
packetSize?: number | undefined;
|
|
20
40
|
}
|
|
21
|
-
export declare function sendV1({ pool,
|
|
22
|
-
export declare const SendV2Flags: {
|
|
23
|
-
readonly None: 0;
|
|
24
|
-
readonly Brotli: 1;
|
|
25
|
-
readonly Lz4: 2;
|
|
26
|
-
readonly Zstd: 4;
|
|
27
|
-
readonly DryRun: 2147483648;
|
|
28
|
-
};
|
|
29
|
-
export type SendV2Flags = (typeof SendV2Flags)[keyof typeof SendV2Flags];
|
|
41
|
+
export declare function sendV1({ pool, path, type, permission, mtime, packetSize, }: SendV1Options): Promise<SendSession>;
|
|
30
42
|
export declare const SendV2Request: import("@yume-chan/struct").Struct<{
|
|
31
43
|
id: import("@yume-chan/struct").NumberField<number>;
|
|
32
44
|
mode: import("@yume-chan/struct").NumberField<number>;
|
|
@@ -37,6 +49,16 @@ export declare const SendV2Request: import("@yume-chan/struct").Struct<{
|
|
|
37
49
|
flags: import("@yume-chan/struct").NumberField<number>;
|
|
38
50
|
}>>;
|
|
39
51
|
export interface SendV2Options extends SendV1Options {
|
|
52
|
+
/**
|
|
53
|
+
* The format to compress the file stream for sending.
|
|
54
|
+
*
|
|
55
|
+
* If the device or current runtime doesn't support the specified format,
|
|
56
|
+
* an Error will be thrown.
|
|
57
|
+
*
|
|
58
|
+
* If `undefined` is specified, no compression will be used.
|
|
59
|
+
* (this behavior is different from `AdbSync.Service.prototype.write`,
|
|
60
|
+
* which will automatically choose the best format)
|
|
61
|
+
*/
|
|
40
62
|
compression?: Compression.Format | undefined;
|
|
41
63
|
/**
|
|
42
64
|
* Don't write the file to disk. Requires the `sendrecv_v2` feature.
|
|
@@ -46,9 +68,9 @@ export interface SendV2Options extends SendV1Options {
|
|
|
46
68
|
*/
|
|
47
69
|
dryRun?: boolean | undefined;
|
|
48
70
|
}
|
|
49
|
-
export declare function sendV2({ pool,
|
|
71
|
+
export declare function sendV2({ pool, path, type, permission, mtime, packetSize, compression, dryRun, }: SendV2Options): Promise<SendSession>;
|
|
50
72
|
export interface SendOptions extends SendV2Options {
|
|
51
73
|
version: 1 | 2;
|
|
52
74
|
}
|
|
53
|
-
export declare function send(options: SendOptions): Promise<
|
|
75
|
+
export declare function send(options: SendOptions): Promise<SendSession>;
|
|
54
76
|
//# sourceMappingURL=push.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/request/push.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../../src/service/sync/request/push.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,cAAc,EAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGH,eAAe,EAClB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAMpD,eAAO,MAAM,aAAa,QAAY,CAAC;AAEvC,eAAO,MAAM,UAAU;;;;GAAkD,CAAC;AAE1E,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC,eAAe,CAAC,U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
-
import {
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { DelayedCloseWritableStream, DistributionStream, MaybeConsumable, } from "@yume-chan/stream-extra";
|
|
2
3
|
import { struct, u32 } from "@yume-chan/struct";
|
|
3
|
-
import { NOOP } from "../../../utils/
|
|
4
|
+
import { NOOP } from "../../../utils/no-op.js";
|
|
4
5
|
import { LinuxFileType } from "../android.js";
|
|
5
6
|
import { Compression } from "../compression/index.js";
|
|
6
7
|
import { RequestId, ResponseId } from "../id/index.js";
|
|
7
8
|
import { Error as AdbSyncError } from "../socket.js";
|
|
9
|
+
import { SyncFlag } from "./flag.js";
|
|
8
10
|
export const MaxPacketSize = 64 * 1024;
|
|
9
11
|
export const OkResponse = struct({ unused: u32 }, { littleEndian: true });
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
class SendWritableStream extends MaybeConsumable.WritableStream {
|
|
13
|
+
#pool;
|
|
14
|
+
#socket;
|
|
15
|
+
#resolver = new PromiseResolver();
|
|
16
|
+
#controller;
|
|
17
|
+
#bytesWritten = 0;
|
|
18
|
+
get bytesWritten() {
|
|
19
|
+
return this.#bytesWritten;
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
constructor(pool, socket, mtime) {
|
|
22
|
+
let controller;
|
|
23
|
+
super({
|
|
24
|
+
start: (controller_) => {
|
|
25
|
+
controller = controller_;
|
|
26
|
+
// Start reading response immediately,
|
|
27
|
+
// the server may send error response before the whole file is sent.
|
|
28
|
+
socket.readResponse(ResponseId.Ok, OkResponse).then(() => this.#finish(), (e) => this.#finish(e));
|
|
29
|
+
},
|
|
30
|
+
write: async (chunk) => {
|
|
31
|
+
try {
|
|
32
|
+
this.#bytesWritten += chunk.length;
|
|
33
|
+
await socket.writeRequest(RequestId.Data, chunk);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
await this.#finish(e);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
close: async () => {
|
|
40
|
+
try {
|
|
41
|
+
await socket.writeRequest(RequestId.Done, mtime);
|
|
42
|
+
await socket.flush();
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
await this.#finish(e);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await this.#resolver.promise;
|
|
49
|
+
},
|
|
50
|
+
abort: async (reason) => {
|
|
51
|
+
// Write anything other than `Data` or `Done`
|
|
52
|
+
// will cause the server to delete the file.
|
|
53
|
+
await socket.writeRequest(ResponseId.Fail, 0);
|
|
54
|
+
// Socket not reusable after aborting, so discard it.
|
|
55
|
+
await this.#finish(reason);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
this.#pool = pool;
|
|
59
|
+
this.#socket = socket;
|
|
60
|
+
this.#controller = controller;
|
|
61
|
+
// Suppress unhandled rejection warning when the promise is not awaited.
|
|
62
|
+
this.#resolver.promise.catch(NOOP);
|
|
63
|
+
}
|
|
64
|
+
#trySetError(reason) {
|
|
65
|
+
try {
|
|
66
|
+
this.#controller.error(reason);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Ignore if controller is already closed or errored
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async #finish(error) {
|
|
73
|
+
try {
|
|
74
|
+
await this.#pool.release(this.#socket, !(error instanceof AdbSyncError));
|
|
75
|
+
if (error) {
|
|
76
|
+
this.#trySetError(error);
|
|
77
|
+
this.#resolver.reject(error);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.#resolver.resolve();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
const finalError =
|
|
85
|
+
// Use SuppressedError if available and there is an existing error.
|
|
86
|
+
error && typeof SuppressedError !== "undefined"
|
|
87
|
+
? new SuppressedError(e, error)
|
|
88
|
+
: e;
|
|
89
|
+
this.#trySetError(finalError);
|
|
90
|
+
this.#resolver.reject(finalError);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export async function sendV1({ pool, path, type = LinuxFileType.File, permission = 0o666, mtime = (Date.now() / 1000) | 0, packetSize = MaxPacketSize, }) {
|
|
95
|
+
const mode = (type << 12) | permission;
|
|
96
|
+
const request = path + "," + mode;
|
|
97
|
+
const socket = await pool.acquire();
|
|
32
98
|
try {
|
|
33
|
-
await socket.
|
|
99
|
+
await socket.writeRequest(RequestId.Send, request);
|
|
34
100
|
}
|
|
35
101
|
catch (e) {
|
|
36
|
-
|
|
102
|
+
await pool.release(socket, !(e instanceof AdbSyncError));
|
|
37
103
|
throw e;
|
|
38
104
|
}
|
|
105
|
+
const distributeStream = new DistributionStream(packetSize, true);
|
|
106
|
+
const sendStream = new SendWritableStream(pool, socket, mtime);
|
|
107
|
+
return {
|
|
108
|
+
writable: new DelayedCloseWritableStream(distributeStream.writable, distributeStream.readable.pipeTo(sendStream)),
|
|
109
|
+
get bytesWritten() {
|
|
110
|
+
return sendStream.bytesWritten;
|
|
111
|
+
},
|
|
112
|
+
get bytesCompressed() {
|
|
113
|
+
return sendStream.bytesWritten;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
39
116
|
}
|
|
40
|
-
export function sendV1({ pool, filename, file, type = LinuxFileType.File, permission = 0o666, mtime = (Date.now() / 1000) | 0, packetSize = MaxPacketSize, }) {
|
|
41
|
-
return pool.withSocket(async (socket) => {
|
|
42
|
-
const mode = (type << 12) | permission;
|
|
43
|
-
const pathAndMode = `${filename},${mode.toString()}`;
|
|
44
|
-
await socket.writeRequest(RequestId.Send, pathAndMode);
|
|
45
|
-
await pipeFileData(socket, file, packetSize, mtime, Compression.Format.None);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
export const SendV2Flags = {
|
|
49
|
-
None: 0,
|
|
50
|
-
Brotli: 1,
|
|
51
|
-
Lz4: 2,
|
|
52
|
-
Zstd: 4,
|
|
53
|
-
DryRun: 0x80000000,
|
|
54
|
-
};
|
|
55
117
|
export const SendV2Request = struct({ id: u32, mode: u32, flags: u32 }, { littleEndian: true });
|
|
56
|
-
export function sendV2({ pool,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
118
|
+
export async function sendV2({ pool, path, type = LinuxFileType.File, permission = 0o666, mtime = (Date.now() / 1000) | 0, packetSize = MaxPacketSize, compression = Compression.Format.None, dryRun = false, }) {
|
|
119
|
+
let flags = SyncFlag.None;
|
|
120
|
+
let compressStream;
|
|
121
|
+
// Validate `compression` before acquiring the socket
|
|
122
|
+
switch (compression) {
|
|
123
|
+
case Compression.Format.Brotli:
|
|
124
|
+
flags |= SyncFlag.Brotli;
|
|
125
|
+
compressStream = Compression.createCompressionStream(Compression.Format.Brotli);
|
|
126
|
+
break;
|
|
127
|
+
case Compression.Format.Lz4:
|
|
128
|
+
flags |= SyncFlag.Lz4;
|
|
129
|
+
compressStream = Compression.createCompressionStream(Compression.Format.Lz4);
|
|
130
|
+
break;
|
|
131
|
+
case Compression.Format.Zstd:
|
|
132
|
+
flags |= SyncFlag.Zstd;
|
|
133
|
+
compressStream = Compression.createCompressionStream(Compression.Format.Zstd);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (dryRun) {
|
|
137
|
+
flags |= SyncFlag.DryRun;
|
|
138
|
+
}
|
|
139
|
+
const socket = await pool.acquire();
|
|
140
|
+
try {
|
|
141
|
+
await socket.writeRequest(RequestId.SendV2, path);
|
|
74
142
|
await socket.write(SendV2Request.serialize({
|
|
75
143
|
id: RequestId.SendV2,
|
|
76
144
|
mode: (type << 12) | permission,
|
|
77
145
|
flags,
|
|
78
146
|
}));
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
await pool.release(socket, !(e instanceof AdbSyncError));
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
const distributeStream = new DistributionStream(packetSize, true);
|
|
153
|
+
const sendStream = new SendWritableStream(pool, socket, mtime);
|
|
154
|
+
if (!compressStream) {
|
|
155
|
+
return {
|
|
156
|
+
writable: new DelayedCloseWritableStream(distributeStream.writable, distributeStream.readable.pipeTo(sendStream)),
|
|
157
|
+
get bytesWritten() {
|
|
158
|
+
return sendStream.bytesWritten;
|
|
159
|
+
},
|
|
160
|
+
compression: Compression.Format.None,
|
|
161
|
+
get bytesCompressed() {
|
|
162
|
+
return sendStream.bytesWritten;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
let bytesWritten = 0;
|
|
167
|
+
return {
|
|
168
|
+
writable: new DelayedCloseWritableStream(new MaybeConsumable.WrapWritableStream(compressStream.writable, {
|
|
169
|
+
write(chunk) {
|
|
170
|
+
bytesWritten += chunk.length;
|
|
171
|
+
},
|
|
172
|
+
}), compressStream.readable
|
|
173
|
+
.pipeThrough(distributeStream)
|
|
174
|
+
.pipeTo(sendStream)),
|
|
175
|
+
get bytesWritten() {
|
|
176
|
+
return bytesWritten;
|
|
177
|
+
},
|
|
178
|
+
compression,
|
|
179
|
+
get bytesCompressed() {
|
|
180
|
+
return sendStream.bytesWritten;
|
|
181
|
+
},
|
|
182
|
+
};
|
|
81
183
|
}
|
|
82
184
|
export function send(options) {
|
|
83
185
|
if (options.version === 2) {
|