title: How to emit/pipe array values as a readable stream in node.js?
body: <p>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 <a href="https://github.com/substack/stream-handbook" rel="noreferrer">example</a> using setInterval and I can implement that successfully using 0 for the interval value, but I am iterating over a lot of data and triggering gc every time is slowing things down.</p>
  
  <pre><code>// Working with the setInterval wrapper
  var arr = [1, 5, 3, 6, 8, 9];
  
  function createStream () {
      var t = new stream;
      t.readable = true;
      var times = 0;
      var iv = setInterval(function () {
          t.emit('data', arr[times]);
          if (++times === arr.length) {
              t.emit('end');
              clearInterval(iv);
          }
      }
  }, 0);
  
  // Create the writable stream s
  // ....
  
  createStream().pipe(s);
  </code></pre>
  
  <p>What I would like to do is emit values without the setInterval. Perhaps using the async module like this:</p>
  
  <pre><code>async.forEachSeries(arr, function(item, cb) {
      t.emit('data', item);
      cb();
  }, function(err) {
   if (err) {
       console.log(err);
   }
   t.emit('end');
  });
  </code></pre>
  
  <p>In this case I iterate the array and emit data, but never pipe any values. I have already seen shinout's <a href="https://github.com/shinout/ArrayStream" rel="noreferrer">ArrayStream</a>, but I think that was created before v0.10 and it is a bit more overhead than I am looking for.</p>