How to emit/pipe array values as a readable stream in node.js?

前端 未结 5 2316
梦谈多话
梦谈多话 2021-02-07 09:23

What is the best way to create a readable stream from an array and pipe values to a writable stream? I have seen substack\'s example using setInterval and I can implement that s

5条回答
  •  忘掉有多难
    2021-02-07 10:08

    It's an old question, but if anyone stumbles on this, node-stream-array is a much simpler and more elegant implementation for Node.js >= v0.10

    var streamify = require('stream-array'),
      os = require('os');
    
    streamify(['1', '2', '3', os.EOL]).pipe(process.stdout);
    

提交回复
热议问题