/**
 * Copy given `source` stream to `targets`.
 *
 * For example, copying process.stdout to a file:
 *
 *     var stream = require('stream');
 *     stream.copy = require('stream-copy').copy;
 *
 *     stream.copy(process.stdout, fs.createWriteStream(filename));
 *
 * @param {stream.Writable} source
 * @param {stream.Writable} targets Stream or multiple streams to copy to.
 * @link https://github.com/alexmingoia/stream-copy
 * @api public
 */

exports.copy = function(source, targets) {
  targets = Array.prototype.slice.call(arguments, 1);
  var write = source.write;
  source.write = function() {
    var args = Array.prototype.slice.call(arguments);
    write.apply(this, args);
    for (var len = targets.length, i=0; i<len; i++) {
      targets[i].write.apply(targets[i], args);
    }
  };
};
