// Generated by IcedCoffeeScript 1.7.1-f
(function() {
  var Drain, drain, stream,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  stream = require('stream');

  exports.Drain = Drain = (function(_super) {
    __extends(Drain, _super);

    function Drain() {
      this._bufs = [];
      Drain.__super__.constructor.apply(this, arguments);
    }

    Drain.prototype._write = function(data, encoding, cb) {
      this._bufs.push(data);
      return cb(null);
    };

    Drain.prototype.data = function() {
      return Buffer.concat(this._bufs);
    };

    return Drain;

  })(stream.Writable);

  exports.drain = drain = function(strm, cb) {
    var d, done;
    d = new Drain();
    strm.pipe(d);
    done = function(err, data) {
      var tmp;
      if ((tmp = cb) != null) {
        cb = null;
        return tmp(err, data);
      }
    };
    d.on('finish', function() {
      return done(null, d.data());
    });
    return d.on('error', function(err) {
      return done(err, null);
    });
  };

}).call(this);
