title: Node - how can i pipe to a new READABLE stream?
body: <p>My app is supposed to take Web Audio streamed from the client, encode it as MP3, before sending it back out to clients via WebSocket.</p>
  <p>I can currently encode and pipe to a file like this:</p>
  <pre><code>inbound_stream.pipe(encoder).pipe(fs.createWriteStream('audio.mp3'));
  </code></pre>
  <p>And if I <em>already</em> have a file on the server I can do this:</p>
  <pre><code>var mp3File = fs.createReadStream('audio.mp3');
            
              mp3File.on('data', function(buffer){
                  io.sockets.emit('audio', { buffer: buffer });
              });
  </code></pre>
  <p>However, I want to access the encoded chunks in real time, and send those out to clients - <em>not</em> write to a file.</p>
  <p>What I want is this, effectively:</p>
  <pre><code>inbound_stream.pipe(encoder).pipe(newReadStream);
  
          newReadStream.on('data', function(buffer){
              io.sockets.emit('audio', { buffer: buffer });
          });
  </code></pre>
  <p>I've looked at Duplex and Transform streams, but frankly I am still learning and the Prototyping made my head spin.</p>
  <p>How do I do this? Thanks.</p>
  <h1>UPDATE</h1>
  <p>The solution below from @Nazar Sakharenko certainly does what I wanted, but the overhead of live encoding seems to make this inpossible, so writing the encoded MP3, and pre-buffering it seems to be the only way (thanks to various people for the suggestion.)</p>
  <p>However I still have problems with this approach. New question here:</p>
  <p><a href="https://stackoverflow.com/questions/38727384/node-js-create-a-new-readstream-for-a-new-file-when-that-file-reaches-a-certa">node.js - create a new ReadStream for a new file, when that file reaches a certain size</a></p>