From 5b6c3165136bfb320615dd2e8c12fcceceeb3164 Mon Sep 17 00:00:00 2001 From: almenon Date: Sat, 27 Mar 2021 16:02:43 -0700 Subject: [PATCH] add example of NewlineTransformer [skip ci] --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e408cb5..be2fba1 100644 --- a/README.md +++ b/README.md @@ -332,7 +332,27 @@ If the process could not be spawned please double-check that python can be launc ### NewlineTransformer -A utility class for splitting stream data into newlines. Used as the default for stdoutSplitter and stderrSplitter if they are unspecified. You can use this class for any extra python streams if you'd like. +A utility class for splitting stream data into newlines. Used as the default for stdoutSplitter and stderrSplitter if they are unspecified. You can use this class for any extra python streams if you'd like. For example: + +```python +# foo.py +print('hello world', file=open(3, "w")) +``` + +```typescript +import { PythonShell, NewlineTransformer, Options } from 'python-shell' + +const options: Options = { + 'stdio': + ['pipe', 'pipe', 'pipe', 'pipe'] // stdin, stdout, stderr, custom +} +const pyshell = new PythonShell('foo.py', options) + +const customPipe = pyshell.childProcess.stdio[3] +customPipe.pipe(new NewlineTransformer()).on('data', (customResult: Buffer) => { + console.log(customResult.toString()) +}) +``` ## Used By: