<commit_before>var util = require('util')
	, EventEmitter = require('events').EventEmitter
	, parser = require('./messageParser')
	, framer = require('./lengthPrefixMessageFramer')

module.exports = MessageReceiver


function MessageReceiver() {
	if(!(this instanceof MessageReceiver)) {
		return new MessageReceiver()
	}

	EventEmitter.call(this)

	this._incompletePacket = null
}
util.inherits(MessageReceiver, EventEmitter)

MessageReceiver.prototype.processData = function(data) {
	if(this._incompletePacket) {
		data = this._combineWithIncompletePacket(data)
  }

  var contentLength = framer.getContentLength(data)
  	, expectedPacketLength = contentLength + 4

  if(data.length === expectedPacketLength) {
  	this._handleCompletePacket(data)
  } else if (data.length > expectedPacketLength) {
  	this._handleMultiplePackets(data, expectedPacketLength)
  } else {
    this._handleIncompletePacket(data, expectedPacketLength)
  }
}

MessageReceiver.prototype._combineWithIncompletePacket = function(packet) {
  var newPacket = new Buffer(incompletePacket.length + packet.length)
  this._incompletePacket.copy(newPacket, 0)
  packet.copy(newPacket, incompletePacket.length)
  this._incompletePacket = null
  return newPacket
}

MessageReceiver.prototype._handleCompletePacket = function(packet) {
	var unframedPacket = framer.unframe(packet)
	this.emit('message', unframedPacket)
}

MessageReceiver.prototype._handleIncompletePacket = function(packet, expectedPacketLength) {
  //console.log('Incomplete Packet (wanted: ' + expectedPacketLength + " bytes, got: " + packet.length + " bytes)")
	this._incompletePacket = packet
}

MessageReceiver.prototype._handleMultiplePackets = function(packet, expectedPacketLength) {
  //console.log("Packet too big, trying to split into multiple packets (wanted: " + expectedPacketLength + " bytes, got: " + packet.length + " bytes)")
  this.processData(packet.slice(0, expectedPacketLength))
  this.processData(packet.slice(expectedPacketLength))
}<commit_msg>Fixed broken function in message receiver<commit_after>var util = require('util')
	, EventEmitter = require('events').EventEmitter
	, parser = require('./messageParser')
	, framer = require('./lengthPrefixMessageFramer')

module.exports = MessageReceiver


function MessageReceiver() {
	if(!(this instanceof MessageReceiver)) {
		return new MessageReceiver()
	}

	EventEmitter.call(this)

	this._incompletePacket = null
}
util.inherits(MessageReceiver, EventEmitter)

MessageReceiver.prototype.processData = function(data) {
	if(this._incompletePacket) {
		data = this._combineWithIncompletePacket(data)
  }

  var contentLength = framer.getContentLength(data)
  	, expectedPacketLength = contentLength + 4

  if(data.length === expectedPacketLength) {
  	this._handleCompletePacket(data)
  } else if (data.length > expectedPacketLength) {
  	this._handleMultiplePackets(data, expectedPacketLength)
  } else {
    this._handleIncompletePacket(data, expectedPacketLength)
  }
}

MessageReceiver.prototype._combineWithIncompletePacket = function(packet) {
  var newPacket = new Buffer(this._incompletePacket.length + packet.length)
  this._incompletePacket.copy(newPacket, 0)
  packet.copy(newPacket, this._incompletePacket.length)
  this._incompletePacket = null
  return newPacket
}

MessageReceiver.prototype._handleCompletePacket = function(packet) {
	var unframedPacket = framer.unframe(packet)
	this.emit('message', unframedPacket)
}

MessageReceiver.prototype._handleIncompletePacket = function(packet, expectedPacketLength) {
  //console.log('Incomplete Packet (wanted: ' + expectedPacketLength + " bytes, got: " + packet.length + " bytes)")
	this._incompletePacket = packet
}

MessageReceiver.prototype._handleMultiplePackets = function(packet, expectedPacketLength) {
  //console.log("Packet too big, trying to split into multiple packets (wanted: " + expectedPacketLength + " bytes, got: " + packet.length + " bytes)")
  this.processData(packet.slice(0, expectedPacketLength))
  this.processData(packet.slice(expectedPacketLength))
}
{'fraction_non_alphanumeric': 0.10979228486646884, 'fraction_numerical': 0.001483679525222552, 'mean_word_length': 5.998269896193771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '200810', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1141, 'n_words': 211}