feat(stream): improve ConcatStringStream

This commit is contained in:
Simon Chan 2023-07-06 15:07:08 +08:00
parent e3bfd1592f
commit 721e14fa7a
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
16 changed files with 380 additions and 72 deletions

View file

@ -10,7 +10,7 @@ import {
AdbSubprocessNoneProtocol,
AdbSubprocessShellProtocol,
} from "@yume-chan/adb";
import { DecodeUtf8Stream, GatherStringStream } from "@yume-chan/stream-extra";
import { ConcatStringStream, DecodeUtf8Stream } from "@yume-chan/stream-extra";
export class Cmd extends AdbCommandBase {
#supportsShellV2: boolean;
@ -82,18 +82,19 @@ export class Cmd extends AdbCommandBase {
): Promise<AdbSubprocessWaitResult> {
const process = await this.spawn(true, command, ...args);
const stdout = new GatherStringStream();
const stderr = new GatherStringStream();
const [, , exitCode] = await Promise.all([
process.stdout.pipeThrough(new DecodeUtf8Stream()).pipeTo(stdout),
process.stderr.pipeThrough(new DecodeUtf8Stream()).pipeTo(stderr),
const [stdout, stderr, exitCode] = await Promise.all([
process.stdout
.pipeThrough(new DecodeUtf8Stream())
.pipeThrough(new ConcatStringStream()),
process.stderr
.pipeThrough(new DecodeUtf8Stream())
.pipeThrough(new ConcatStringStream()),
process.exit,
]);
return {
stdout: stdout.result,
stderr: stderr.result,
stdout,
stderr,
exitCode,
};
}