Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 理解节点流操作序列_Javascript_Node.js_Stream - Fatal编程技术网

Javascript 理解节点流操作序列

Javascript 理解节点流操作序列,javascript,node.js,stream,Javascript,Node.js,Stream,我正在学习使用Stream Adventure()的节点流。 我很难理解HTML流课程 这就是挑战: 您的程序将获得一些写入stdin的html。转换所有 对于类名为“loud”的元素,将内部html改为大写 您可以使用喇叭和通过来解决此冒险 我找到了解决办法: 我似乎无法理解上面的程序流程 即使没有使用上述流的引用/回调,最后两行如何修改流输出?关键是异步思考。将process.stdin.pipe(tr).pipe(process.stdout)想象为“将输入输入输入到tr中,我们将在后面详

我正在学习使用Stream Adventure()的节点流。 我很难理解HTML流课程

这就是挑战:

您的程序将获得一些写入stdin的html。转换所有 对于类名为“loud”的元素,将内部html改为大写

您可以使用
喇叭
通过
来解决此冒险

我找到了解决办法:

我似乎无法理解上面的程序流程


即使没有使用上述流的引用/回调,最后两行如何修改流输出?

关键是异步思考。将
process.stdin.pipe(tr).pipe(process.stdout)
想象为“将输入输入输入到tr中,我们将在后面详细介绍,然后打印到stdout”

然后,我们在下面填写逻辑并准确说明
tr
将对输入做什么。此程序中只有一个
tr
对象。而
对象就是根据它来定义的。底部使用
stream
的代码正在处理用于过滤
stdin
stdout
的相同
tr

记住提示现在
stream
'输出所有内部html内容。哔哔声'
,您写入
stream
的数据将显示为新的内部html内容。这正是最后一行所做的。

我不熟悉它,但“tr”不会已经通过管道传输到process.stdin?有一个,还有一个
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)