<commit_before>var Structr = require('structr'),
EventEmitter = require('sk/core/events').EventEmitter;

/**
 the bridge between the listener, and responder. Yeah, Yeah. the listener
94 */

var proto = {

	/**
	 */

	'_init': function(ttl)
	{
		this._em = new EventEmitter();	

		this.response = {};

		if(ttl)
		{
			this.cache(ttl);
		}
	},

	/**
	 */

	'cache': function(ttl)
	{
		if(this._caching) return;
		this._caching = true;


		//store the buffer incase data comes a little quicker than we can handle it.
		var buffer = this._buffer = [], self = this;

		this.on({
			write: function(chunk)
			{
				buffer.push(chunk)
			}
		});
	},

	/**
	 */

	'on': function(listeners)
	{
		for(var type in listeners)
		{
			this._em.addListener(type, listeners[type]);
		}
	},


	/**
	 */

	'second on': function(type, callback)
	{
		this._em.addListener(type, callback);
	},

	/**
	 */

	'respond': function(data)
	{
		Structr.copy(data, this.response, true);
	},

	/**
	 */

	'error': function(data)
	{
		this._em.emit('error', data);
	},

	/**
	 */

	'write': function(data)
	{
		if(!this._sentResponse)
		{
			this._em.emit('response', this.response);<commit_msg>add description, json parse response<commit_after>var Structr = require('structr'),
EventEmitter = require('sk/core/events').EventEmitter;

/**
 the bridge between the listener, and responder. Yeah, Yeah. the listener
94 */

var proto = {

	/**
	 */

	'_init': function(ttl)
	{
		this._em = new EventEmitter();	

		this.response = {};

		if(ttl)
		{
			this.cache(ttl);
		}
	},

	/**
	 */

	'cache': function(ttl)
	{
		if(this._caching) return;
		this._caching = true;


		//store the buffer incase data comes a little quicker than we can handle it.
		var buffer = this._buffer = [], self = this;

		this.on({
			write: function(chunk)
			{
				buffer.push(chunk)
			}
		});
	},

	/**
	 */

	'on': function(listeners)
	{
		for(var type in listeners)
		{
			this._em.addListener(type, listeners[type]);
		}
	},


	/**
	 */

	'second on': function(type, callback)
	{
		this._em.addListener(type, callback);
	},

	/**
	 */

	'respond': function(data)
	{
		Structr.copy(data, this.response, true);
	},

	/**
	 */

	'error': function(data)
	{
		this._em.emit('error', data);
	},

	/**
	 */

	'write': function(data)
	{
		if(!this._sentResponse)
		{

			//WHOOAAHH, what are you doing!? Okay, I know it looks stupid, it is. BUT, consider this scenario:
			//via HTTP, the session object is *saved* to the database once toJSON is called, which is ONLY called when *this* happens.  We do not want
			//the session to save before we're done writing to it, or handling it. 
			this.response = JSON.parse(JSON.stringify(this.response));

			this._em.emit('response', this.response);
{'fraction_non_alphanumeric': 0.17068713450292397, 'fraction_numerical': 0.0014619883040935672, 'mean_word_length': 2.9438040345821324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2002107', 'n_tokens_mistral': 1099, 'n_tokens_neox': 971, 'n_words': 228}