<commit_before>'use strict';

var fs = require('fs');
var readline = require('readline');
var spawn = require('child_process').spawn;
var util = require('util');
var EventEmitter = require('events').EventEmitter;


function PacketReader(monitor_interface) {
    var self = this;
    EventEmitter.call(this);

    var voidStream = fs.createWriteStream('/dev/null'); // Not needed in node v4

    var tcpdumpProcess = spawn('tcpdump', ['-I', '-e', '-q', '-t', '-U', '-i', monitor_interface || 'wlan0mon']);

    var readliner = readline.createInterface({
        input: tcpdumpProcess.stdout,
        output: voidStream
    });

    var errorReader = readline.createInterface({
        input: tcpdumpProcess.stderr,
        output: voidStream
    });

    this.start = function () {
        tcpdumpProcess.on('close', function () {
            readliner.close();
            errorReader.close();
            self.emit('end');
        });

        errorReader.on('line', function (buffer) {
            self.emit('error', buffer.toString());
        });

        readliner.on('line', function (buffer) {
            var line = buffer.toString();
            var match;

            match = line.match(/SA:(..:..:..:..:..:..)/);
            var mac_address = match ? match[1].toUpperCase() : undefined;

            match = line.match(/(-\d{1,2})dB/);
            var signal_strength = match ? match[1] : undefined;

            if (mac_address !== undefined && signal_strength !== undefined) {
                self.emit('packet', {
                    mac_address: mac_address,
                    signal_strength: signal_strength
                });
            }
        });
    };

    this.stop = function () {
        readliner.close();
        errorReader.close();
        tcpdumpProcess.kill();

        readliner = null;
        errorReader = null;
        tcpdumpProcess = null;
        self.emit('end');
    };

}

util.inherits(PacketReader, EventEmitter);

module.exports = PacketReader;<commit_msg>secured stop<commit_after>'use strict';

var fs = require('fs');
var readline = require('readline');
var spawn = require('child_process').spawn;
var util = require('util');
var EventEmitter = require('events').EventEmitter;


function PacketReader(monitor_interface) {
    var self = this;
    EventEmitter.call(this);

    var voidStream = fs.createWriteStream('/dev/null'); // Not needed in node v4

    var tcpdumpProcess = spawn('tcpdump', ['-I', '-e', '-q', '-t', '-U', '-i', monitor_interface || 'wlan0mon']);

    var readliner = readline.createInterface({
        input: tcpdumpProcess.stdout,
        output: voidStream
    });

    var errorReader = readline.createInterface({
        input: tcpdumpProcess.stderr,
        output: voidStream
    });

    this.start = function () {
        tcpdumpProcess.on('close', function () {
            readliner.close();
            errorReader.close();
            self.emit('end');
        });

        errorReader.on('line', function (buffer) {
            self.emit('error', buffer.toString());
        });

        readliner.on('line', function (buffer) {
            var line = buffer.toString();
            var match;

            match = line.match(/SA:(..:..:..:..:..:..)/);
            var mac_address = match ? match[1].toUpperCase() : undefined;

            match = line.match(/(-\d{1,2})dB/);
            var signal_strength = match ? match[1] : undefined;

            if (mac_address !== undefined && signal_strength !== undefined) {
                self.emit('packet', {
                    mac_address: mac_address,
                    signal_strength: signal_strength
                });
            }
        });
    };

    this.stop = function () {
        if (readliner)
            readliner.close();
        if (errorReader)
            errorReader.close();
        if (tcpdumpProcess)
            tcpdumpProcess.kill();

        readliner = null;
        errorReader = null;
        tcpdumpProcess = null;
        self.emit('end');
    };

}

util.inherits(PacketReader, EventEmitter);

module.exports = PacketReader;
{'fraction_non_alphanumeric': 0.15110894467462832, 'fraction_numerical': 0.002924689251767, 'mean_word_length': 2.0950226244343892, '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': '6373842', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1118, 'n_words': 238}