title: Clone a transform stream in NodeJS
body: <p>I'm trying to reuse a couple of transform streams (gulp-like, ie. <code>concat()</code> or <code>uglify()</code>) across several readable streams. I only have access to the created instances and not the original subclasses.</p>
  
  <p>It does not work out of the box, I get <code>Error: stream.push() after EOF</code> when I pipe at lease two distinct readable streams into my transforms. Somehow the events do appear to leak from one stream to the other.</p>
  
  <p>I've tried to setup a cloneTransform function to somehow cleanly "fork" into two distincts transforms, however I can't get it to not share events:</p>
  
  <p><code>function cloneTransform(transform) {
      var ts = new Transform({objectMode: true});
      ts._transform = transform._transform.bind(ts);
      if(typeof transform._flush !== 'undefined') {
        ts._flush = transform._flush.bind(ts);
      }
      return ts;
    }
  </code></p>
  
  <p>Any alternative idea, existing plugin or solution to address this?</p>
  
  <hr>
  
  <h3>Update: context</h3>
  
  <p>I'm working on a rewrite of the gulp-usemin package, it is hosted <a href="https://github.com/mgcrea/gulp-usemin-stream/blob/master/index.js" rel="nofollow">here: gulp-usemin-stream</a>, example use <a href="https://github.com/mgcrea/angular-strap/blob/master/gulpfile.js#L351" rel="nofollow">here</a>.</p>
  
  <p>Basically you parse an index.html looking for comment blocks surrounding styles/scripts declarations, and you want to apply several configurable transformation to theses files (see <a href="https://github.com/yeoman/grunt-usemin" rel="nofollow">grunt-usemin</a>).
  So the problem I'm trying to solve is to reuse an array of transforms, <code>[concat(), uglify()]</code> that are passed as options to a gulp meta transform.</p>