mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-06 03:50:18 +02:00
chore: experimental moving to rush
This commit is contained in:
parent
963ac49d14
commit
d80288ec9b
209 changed files with 9508 additions and 27413 deletions
34
libraries/adb/src/commands/sync/pull.ts
Normal file
34
libraries/adb/src/commands/sync/pull.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import Struct from '@yume-chan/struct';
|
||||
import { AdbBufferedStream } from '../../stream';
|
||||
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
||||
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
||||
|
||||
export const AdbSyncDataResponse =
|
||||
new Struct({ littleEndian: true })
|
||||
.uint32('dataLength')
|
||||
.arrayBuffer('data', { lengthField: 'dataLength' })
|
||||
.extra({ id: AdbSyncResponseId.Data as const });
|
||||
|
||||
const ResponseTypes = {
|
||||
[AdbSyncResponseId.Data]: AdbSyncDataResponse,
|
||||
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncDataResponse.size),
|
||||
};
|
||||
|
||||
export async function* adbSyncPull(
|
||||
stream: AdbBufferedStream,
|
||||
path: string,
|
||||
): AsyncGenerator<ArrayBuffer, void, void> {
|
||||
await adbSyncWriteRequest(stream, AdbSyncRequestId.Receive, path);
|
||||
while (true) {
|
||||
const response = await adbSyncReadResponse(stream, ResponseTypes);
|
||||
switch (response.id) {
|
||||
case AdbSyncResponseId.Data:
|
||||
yield response.data!;
|
||||
break;
|
||||
case AdbSyncResponseId.Done:
|
||||
return;
|
||||
default:
|
||||
throw new Error('Unexpected response id');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue