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

前端 未结 2 2044
我寻月下人不归
我寻月下人不归 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 09:58

    I was confused too and i would express it again with my words:

    tr.select('.loud').createStream() creates a Duplex-Stream which is nothing else than a combined ReadStream and WriteStream

    This Stream recieves all matches in its ReadStream. If you write to the WriteStream, trumpet takes it as match-replace

    This works for me in the same way:

    // create trumpet stream
    var tr = trumpet();
    
    // create stream with selected elems
    var trumpetSelector = tr.select('.loud');
    var upperOut = trumpetSelector.createReadStream();
    var upperIn = trumpetSelector.createWriteStream();
    upperOut.pipe(new UpperCaseTransformer()).pipe(upperIn);
    

    Please correct me if i'm wrong!

提交回复
热议问题