<commit_before>/**
 * Copyright (c) 2012 <NAME>
 * MIT License
 */

(function () {
  "use strict";

  var helpers = require('./helpers.js');
  var path = require('path');
  var core = require(path.join(helpers.core, 'core.js'));

  // get and parse the options
  var options = helpers.getOptions();

  // setup child with automatic respawn
  var child = new core.spawnPump(options);

  // setup pump as daemon
  helpers.sendLineMessage(child.stdin, {
    cmd : 'setup',
    why: process.argv[2] || 'pump start',
    daemon: process.pid,
    message: ""
  });

  // buffer errors
  var errorBuffer = "";
  child.stderr.on('data', function (chunk) {
    errorBuffer += chunk;
  });

  // hande stdout using a lineend protocol
  var watchPid = null;
  var lineStream = helpers.createLineStream(child.stdout);
  lineStream.on('line', function (json) {
    if (json.cmd === 'pid') {
      watchPid = json.pid;
    }
  });

  // handle pump death
  child.on('exit', function () {
    // kill the watched process too
    try {
      process.kill(watchPid);
    } catch (e) {}

    // respaawn pump
    child.respawn();
    helpers.sendLineMessage(child.stdin, {
      cmd : 'setup',<commit_msg>[fix] flush linestream buffer<commit_after>/**
 * Copyright (c) 2012 <NAME>
 * MIT License
 */

(function () {
  "use strict";

  var helpers = require('./helpers.js');
  var path = require('path');
  var core = require(path.join(helpers.core, 'core.js'));

  // get and parse the options
  var options = helpers.getOptions();

  // setup child with automatic respawn
  var child = new core.spawnPump(options);

  // setup pump as daemon
  helpers.sendLineMessage(child.stdin, {
    cmd : 'setup',
    why: process.argv[2] || 'pump start',
    daemon: process.pid,
    message: ""
  });

  // buffer errors
  var errorBuffer = "";
  child.stderr.on('data', function (chunk) {
    errorBuffer += chunk;
  });

  // hande stdout using a lineend protocol
  var watchPid = null;
  var lineStream = helpers.createLineStream(child.stdout);
  lineStream.on('line', function (json) {
    if (json.cmd === 'pid') {
      watchPid = json.pid;
    }
  });

  // handle pump death
  child.on('exit', function () {
    // kill the watched process too
    try {
      process.kill(watchPid);
    } catch (e) {}

    // flush line stream buffer
    lineStream.flush();

    // respaawn pump
    child.respawn();
    helpers.sendLineMessage(child.stdin, {
      cmd : 'setup',
{'fraction_non_alphanumeric': 0.1528402125051083, 'fraction_numerical': 0.004086636697997548, 'mean_word_length': 2.8130841121495327, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3992404', 'n_tokens_mistral': 815, 'n_tokens_neox': 792, 'n_words': 207}