<commit_before>var events = require('events');
var Parser = require('./parser');

/**
 * Handles responses from they hyperdeck.
 */
function ResponseHandler(clientSocket) {
  var destroyed = false;
  var notifier = new events.EventEmitter();
  var buffer = "";
  
  // we have received a complete message when the first line does not end in ":",
  // or the last line is empty
  function isBufferComplete() {
    var lines = buffer.split("\r\n");
    if (lines.length === 1) {
      // is it a single line response?
      return lines[0].indexOf(":") !== lines[0].length-1;
    }
    // multi line response so waiting for a blank line to signify end
    return lines[lines.length-1] === "";
  }
  
  function onData(rawData) {
    buffer += rawData.toString();
    if (!isBufferComplete()) {
      return;
    }
    var data = Parser.parse(buffer);
    // reset buffer
    buffer = "";
  
    switch (data.type) {
      case "synchronousFailure":
      case "synchronousSuccess":
        var response = {<commit_msg>Correctly handle new lines in ResponseHandler<commit_after>var events = require('events');
var Parser = require('./parser');

/**
 * Handles responses from they hyperdeck.
 */
function ResponseHandler(clientSocket) {
  var destroyed = false;
  var notifier = new events.EventEmitter();
  var buffer = "";
  
  function isBufferComplete() {
    var lines = buffer.split("\r\n");
    // there will always be an empty element at the end as every line will always end in "\r\n"
    // so remove it.
    // i.e. "1\r\n2\r\n" => ["1", "2", ""]
    lines.pop();
    if (lines.length === 1) {
      // is it a single line response?
      return lines[0].indexOf(":") !== lines[0].length-1;
    } 
    // multi line response so waiting for a blank line to signify end
    return lines[lines.length-1] === "";
  }
  
  function onData(rawData) {
    buffer += rawData;
    if (!isBufferComplete()) {
      return;
    }
    var data = Parser.parse(buffer);
    // reset buffer
    buffer = "";
  
    switch (data.type) {
      case "synchronousFailure":
      case "synchronousSuccess":
        var response = {
{'fraction_non_alphanumeric': 0.141643059490085, 'fraction_numerical': 0.0066100094428706326, 'mean_word_length': 2.6660899653979238, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 4, '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': '1191154', 'n_tokens_mistral': 636, 'n_tokens_neox': 633, 'n_words': 199}