我目前正在使用模块through2
,concat-stream
和request
在Node.js中使用流实践。动态扩展Node.js中的管道链条
我设置了管链是这样的:
request(process.argv[2])
.pipe(through(write, end))
.pipe(/*And */)
.pipe(/* Some */)
.pipe(/* more */)
.on("finish",function(){ #Do some stuff });
function write(buf, enc, nxt){
/*Push some data after some processing*/
}
function end(done){
done()
}
这是管的静止链。是否可以通过某种形式的用户输入动态指定管道链?
在伪代码:
array_of_user_pipes = from_some_input;
pipe_library = {pipe_name:pipe_callback} object, loaded into application logic
perform the url request (fetch .txt file over the internet)
for all pipe in array_of_user_pipes do
fetch pipe from pipe_library (simple key look-up)
chain pipe to chain
execute the (dynamic) pipe chain
它看起来完全可行的做同样的。您是否遇到过实施此方法的任何具体问题? –
只是不确定如何设置它,因为静态链是通过“方法链”来设置的,如果您正在迭代,这是不可能的,或者有另一种方法来添加管道到链? –