<commit_before>'use strict';
var HOSTS = process.platform === 'win32'
  ? 'C:/Windows/System32/drivers/etc/hosts'
  : '/etc/hosts'
var readFileSync = require('fs').readFileSync;
module.exports = function () {
	return readFileSync(HOSTS, { encoding: 'utf8' })
	  .split(/\r?\n/)
		.map(function(line){
			// R.E from feross/hostile
			var matches = /^\s*?([^#]+?)\s+([^#]+?)$/.exec(line)
		    if (matches && matches.length === 3) {
		      return [matches[1],matches[2]]
				}
		})
		.filter(function(h){return !!h}); // Need to avoid this.
};<commit_msg>Return array of objs and using stream.<commit_after>'use strict';
var once = require('once');
var split = require('split');
var through = require('through');
var readFileSync = require('fs').readFileSync;
var createReadStream = require('fs').createReadStream;
var HOSTS = process.platform === 'win32' ?
	'C:/Windows/System32/drivers/etc/hosts' : '/etc/hosts';
var massageItem = function(line){
    // R.E from feross/hostile
    var matches = /^\s*?([^#]+?)\s+([^#]+?)$/.exec(line)
    if (matches && matches.length === 3) {
        var hostMap = {};
        hostMap[matches[2]] = matches[1]; // host:ip
        return hostMap;
    }
};

var massageData = function(data) {
    return data.split(/\r?\n/)
        .map(massageItem)
        .filter(Boolean);
};

var massageStream = function(){
    return through(function write(data){
        var hostMap = massageItem(data);
        if (hostMap) {
            this.queue(data);
        }
    })
};

module.exports = function(cb) {
    if (typeof cb !== 'function') {
        return massageData(readFileSync(HOSTS, {
            encoding: 'utf8'
        }));
    } else {
        cb = once(cb);
        createReadStream(HOSTS, {
            encoding: 'utf8'
        })
            .pipe(split())
            .pipe(massageStream())
            .on('data', function(data) {
            //Should send the data here.
        })
            .on('error', function(err) {
            cb(err, false);
        })
    }
};
{'fraction_non_alphanumeric': 0.18660049627791564, 'fraction_numerical': 0.008436724565756825, 'mean_word_length': 2.4878892733564015, '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': '1927918', 'n_tokens_mistral': 685, 'n_tokens_neox': 654, 'n_words': 134}