title: How to pipe one readable stream into two writable streams at once in Node.js?
body: <p>The goal is to:</p>
  
  <ol>
  <li>Create a file read stream.</li>
  <li>Pipe it to gzip (<code>zlib.createGzip()</code>)</li>
  <li><p>Then pipe the read stream of zlib output to:</p>
  
  <p>1) HTTP <code>response</code> object</p>
  
  <p>2) <strong>and</strong> writable file stream to save the gzipped output.</p></li>
  </ol>
  
  <p>Now I can do down to 3.1:</p>
  
  <pre><code>var gzip = zlib.createGzip(),
      sourceFileStream = fs.createReadStream(sourceFilePath),
      targetFileStream = fs.createWriteStream(targetFilePath);
  
  response.setHeader('Content-Encoding', 'gzip');
  
  sourceFileStream.pipe(gzip).pipe(response);
  </code></pre>
  
  <p>... which works fine, but I need to also <strong>save the gzipped data to a file</strong> so that I don't need to regzip every time and be able to directly stream the gzipped data as a response.</p>
  
  <p><strong>So how do I pipe one readable stream into two writable streams at once in Node?</strong></p>
  
  <p>Would <code>sourceFileStream.pipe(gzip).pipe(response).pipe(targetFileStream);</code> work in Node 0.8.x?</p>