@@ -7,6 +7,18 @@ export { readSystemdServiceRuntime } from "../daemon/systemd.js";
77
88type ExecFileTailResult = { stdout : string ; stderr : string ; code : number ; truncated : boolean } ;
99
10+ function decodeUtf8Tail ( chunks : Buffer [ ] , truncated : boolean ) : string {
11+ const buffer = Buffer . concat ( chunks ) ;
12+ if ( ! truncated || buffer . length === 0 ) {
13+ return buffer . toString ( "utf8" ) ;
14+ }
15+ let offset = 0 ;
16+ while ( offset < buffer . length && ( buffer [ offset ] & 0xc0 ) === 0x80 ) {
17+ offset += 1 ;
18+ }
19+ return buffer . subarray ( offset ) . toString ( "utf8" ) ;
20+ }
21+
1022export async function execFileUtf8Tail (
1123 command : string ,
1224 args : string [ ] ,
@@ -68,7 +80,7 @@ export async function execFileUtf8Tail(
6880 child . kill ( ) ;
6981 }
7082 resolve ( {
71- stdout : Buffer . concat ( stdoutChunks ) . toString ( "utf8" ) ,
83+ stdout : decodeUtf8Tail ( stdoutChunks , truncated ) ,
7284 stderr : error instanceof Error ? error . message : String ( error ) ,
7385 code : 1 ,
7486 truncated,
@@ -84,7 +96,7 @@ export async function execFileUtf8Tail(
8496 }
8597 settled = true ;
8698 resolve ( {
87- stdout : Buffer . concat ( stdoutChunks ) . toString ( "utf8" ) ,
99+ stdout : decodeUtf8Tail ( stdoutChunks , truncated ) ,
88100 stderr : Buffer . concat ( stderrChunks ) . toString ( "utf8" ) ,
89101 code : typeof code === "number" ? code : 1 ,
90102 truncated,
0 commit comments