stream-utils / duplex-child-process Goto Github PK
View Code? Open in Web Editor NEWSpawn a child process as a duplex stream
Spawn a child process as a duplex stream
It looks like the response is unexpected so it's crashing. Also not sure what's going on with the negative 2 exit code from the command I'm trying to run.
buffer.js:296
throw new TypeError('"list" argument must be an Array of Buffers');
^
TypeError: "list" argument must be an Array of Buffers
at Function.Buffer.concat (buffer.js:296:11)
at ChildProcess.onExit (/var/app/current/node_modules/duplex-child-process/index.js:123:50)
at ChildProcess.g (events.js:291:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Socket.<anonymous> (internal/child_process.js:334:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:498:12)
I output the contents of stderr, code, and signal variables to console to help troubleshoot:
stderr:
null
code:
-2
signal:
null
I'm using Child_Process like this:
await pipeline([
got.stream(url),
DuplexChildProcess.spawn('convert', convertArgs),
DuplexChildProcess.spawn('pngquant', quantArgs),
...
])
If pngquant command fails I have an unhandled error:
/home/.../node_modules/duplex-child-process/index.js:146
cb && cb()
^
TypeError: cb is not a function
at Child_Process.kill (/home/.../node_modules/duplex-child-process/index.js:146:11)
at internal/streams/pipeline.js:47:61
at internal/streams/pipeline.js:83:11
at internal/util.js:392:14
at Child_Process.<anonymous> (internal/streams/pipeline.js:33:21)
at Child_Process.<anonymous> (internal/util.js:392:14)
at Child_Process.onerror (internal/streams/end-of-stream.js:54:14)
at Child_Process.emit (events.js:321:20)
at ChildProcess.onExit (/home/.../node_modules/duplex-child-process/index.js:119:12)
at Object.onceWrapper (events.js:428:26)
at ChildProcess.emit (events.js:321:20)
at maybeClose (internal/child_process.js:1026:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
readable.destroy() and writable.destroy() expect an error argument: https://nodejs.org/api/stream.html#stream_readable_destroy_error
But Child_Process sets this function for destroy method:
this.kill = this.destroy = kill
And this function expects a cb:
function kill(cb) {
that._stdout.destroy()
that._stderr.destroy()
killed = true
try {
that._process.kill((options && options.killSignal) || 'SIGTERM')
} catch (e) {
ex = e
onExit()
}
console.log('cb', cb, new Error().stack)
cb && cb()
}
Wrapper.call(this)
againI have this small js script.
const childProcess = require('duplex-child-process');
const { Readable, Transform } = require('stream');
const reader = new Readable({
encoding: 'utf-8',
});
const transformer = new Transform({
transform: (chunk, encoding, callback) => {
console.log('chunk:', chunk.toString());
callback(null, chunk);
}
});
reader
.pipe(childProcess.spawn('./hellowolrd.py'))
.pipe(transformer)
reader.push('This is a test.\n');
reader.push('This is a test.\n');
reader.push('This is a test.\n');
reader.push(null);
It calls this small python script that just write stdin to sdout.
#!/usr/bin/env python3
import sys
def main():
for line in sys.stdin:
sys.stdout.write(line)
if __name__ == '__main__':
main()
I'm expecting to have this result:
chunk: This is a test.
chunk: This is a test.
chunk: This is a test.
But I have this:
chunk: This is a test.
This is a test.
This is a test.
It seems that chunks are concatenated before being sent to the next stream.
Is this normal behaviour ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.