{"size": 888, "ext": "js", "max_stars_repo_path": "lib/attitude/random.js", "max_stars_repo_name": "markstory/jerkbot", "max_stars_repo_stars_event_min_datetime": "2015-11-08T06:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T06:31:06.000Z", "max_issues_repo_path": "lib/attitude/random.js", "max_issues_repo_name": "markstory/jerkbot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/attitude/random.js", "max_forks_repo_name": "markstory/jerkbot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.2, "max_line_length": 90, "alphanum_fraction": 0.6779279279}
/**
 * Random attitude, will pipe content from /dev/urandom up to a maxsize, defaulting to 1MB
 *
 */
var Base = require('./base'),
	util = require('util'),
	fs = require('fs');

var Random = function () {

};

util.inherits(Random, Base);

Random.prototype.config = function (config) {
	Base.prototype.config.call(this, config);
	this._maxsize = config.maxsize || 1000000
	this._code = config.code || 200;
	this._headers = config.headers || {};
};

Random.prototype.run = function (serverResponse) {
	var urandom = fs.createReadStream('/dev/urandom'),
		maxsize = this._maxsize,
		cursize = 0;
	
	serverResponse.writeHead(this._code, this._headers);

	urandom.setEncoding('utf8');
	urandom.on('data', function (data) {
		cursize += data.length;
		serverResponse.write(data);
		if (cursize >= maxsize) {
			urandom.destroy();
			serverResponse.end();
		}
	});
};

module.exports = Random;