Skip to content

Commit 233603a

Browse files
addaleaxVerteDinde
andauthored
fix: properly handle child process stdio chunking (#409)
* fix: properly handle child process stdio chunking Converting individual chunks from UTF-8 to JS strings is problematic because it does not handle UTF-8 characters that are split across chunks properly. Use the proper way of reading string data from streams instead. * fix: update bufHandler after main merge --------- Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
1 parent 0ad8e20 commit 233603a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/spawn-promise.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ export default function spawn(exe: string, params: string[], opts?: SpawnOptions
3333
if (--refCount <= 0 && !rejected) resolve(stdout);
3434
};
3535

36-
const bufHandler = (b: Buffer): void => {
37-
const chunk = b.toString();
36+
const bufHandler = (chunk: string): void => {
3837
stdout += chunk;
3938
};
4039

41-
proc.stdout.on('data', bufHandler);
40+
proc.stdout.setEncoding('utf8').on('data', bufHandler);
4241
proc.stdout.once('close', release);
43-
proc.stderr.on('data', bufHandler);
42+
proc.stderr.setEncoding('utf8').on('data', bufHandler);
4443
proc.stderr.once('close', release);
4544
proc.on('error', (e: Error): void => reject(e));
4645

0 commit comments

Comments
 (0)