1
我正在学习使用流 - 冒险节点流(https://github.com/substack/stream-adventure)。 我很难理解HTML流课程。了解节点流操作序列
这是挑战:
你的程序将获得一些HTML编写到标准输入。对于类名为“loud”的元素,将所有 内部html转换为大写。
您可以使用
trumpet
和through
来解决这个冒险。
我找到了解决办法here:
var trumpet = require('trumpet');
var through = require('through');
var to_upper = function (buffer) {
this.queue(buffer.toString().toUpperCase())
};
var tr = trumpet();
// Here I expect the output to stdout to have printed as is.
process.stdin.pipe(tr).pipe(process.stdout);
// In the below lines, there is no reference to the above stream
// which should have already started to send to stdout.
// How are the lines below modifying the above stream?
var stream = tr.select('.loud').createStream()
stream.pipe(through(to_upper)).pipe(stream)
我似乎无法理解程序流上面。
即使没有引用/回调使用上述流,最后两行如何修改流输出?
我不熟悉它,但不会'tr'已经管理到process.stdin? – webduvet
有一个[类似的问题](http://stackoverflow.com/questions/24103981/how-does-piping-a-stream-back-to-itself-work-with-trumpet),和[讨论]( https://github.com/nodeschool/discussions/issues/346) –