How does piping a stream back to itself work with Trumpet?

前端 未结 2 2006
我寻月下人不归
我寻月下人不归 2021-02-05 09:24

Learning node.js. Trumpet works by piping a stream back to itself, apparently, so the processed data can then be output. This makes no sense to me, since it seems to be like c

2条回答
  •  伪装坚强ぢ
    2021-02-05 10:01

    I had the exact same confusion:

    davecocoa had this to say to me at the nodeschool.io discussions thread on github. Below is an extract from https://github.com/nodeschool/discussions/issues/346


    I think you might be confusing the two streams loud and tr.

    tr is the main trumpet stream

    • It is a transform stream (has input and output like a pipe)
    • It takes html as input
    • It outputs html
    • we connect stdin to its input, and we connect its output to stdout

    We created loud by asking tr to select html elements with class loud

    • It is a duplex stream (has input and output like a telephone)
    • it outputs or sends html elements
    • it also receives html elements

    tr behaves such that, when html is streamed to it, if there are elements with class loud, they are output from loud, which sends them to the through stream you built for making the text uppercase, which sends them to back to loud's input, where they are reinserted into the html tr originally received and output from tr.

    I guess an important thing to note is that, although loud has an important connection with tr, they are not actually piped together at all.


提交回复
热议问题