<commit_before>var Stream = require('stream');
var util = require('util');

var Response = module.exports = function (res) {
    this.offset = 0;
    this.readable = true;
};

util.inherits(Response, Stream);

var capable = {
    streaming : false,
    status2 : true
};

function parseHeaders (res) {
	var headers = {};
	
	res.headers.forEach(function (h) {
		headers[h.name.toLowerCase()] = h.value;
	});
	
    return headers;
}

Response.prototype.getResponse = function (res) {
	return res.data;
}

Response.prototype.getHeader = function (key) {
    return this.headers[key.toLowerCase()];
};

Response.prototype.handle = function (req) {
	var self = this;
	
	req.onerror = function (error) {
		// TODO: better handling
		// TODO: investigate why make_request returns OBJECT??
		self.emit('ready');
		self.emit('error', new Error('random error'));
		//
		//
	};
	
	req.onabort = function () {
		// TODO: better handling
		self.emit('ready');
		self.emit('error', new Error('aborted'));
		//
	};
	
	req.ontimeout = function () {
		// TODO: better handling
		self.emit('ready');
		self.emit('error', new Error('time out'));
		//
	};
	
	req.onload = function (res) {
		self.statusCode = res.code;
		self.headers = parseHeaders(res);
		
		self.emit('ready');
		
		self._emitData(res);
		
		self.emit('end');
		self.emit('close');
	};
};

Response.prototype._emitData = function (res) {
    var respBody = this.getResponse(res);
	
	if (!respBody) {
		return;
	}
	
    if (respBody.toString().match(/ArrayBuffer/)) {
        this.emit('data', new Uint8Array(respBody, this.offset));
        this.offset = respBody.byteLength;
        return;
    }
    if (respBody.length > this.offset) {
        this.emit('data', respBody.slice(this.offset));
        this.offset = respBody.length;
    }
};

var isArray = Array.isArray || function (xs) {
    return Object.prototype.toString.call(xs) === '[object Array]';
};
<commit_msg>Fixed typo.<commit_after>var Stream = require('stream');
var util = require('util');

var Response = module.exports = function (res) {
    this.offset = 0;
    this.readable = true;
};

util.inherits(Response, Stream);

var capable = {
    streaming : false,
    status2 : true
};

function parseHeaders (res) {
	var headers = {};
	
	res.headers.forEach(function (h) {
		headers[h.name.toLowerCase()] = h.value;
	});
	
    return headers;
}

Response.prototype.getResponse = function (res) {
	return res.data;
}

Response.prototype.getHeader = function (key) {
    return this.headers[key.toLowerCase()];
};

Response.prototype.handle = function (req) {
	var self = this;
	
	req.onerror = function (error) {
		// TODO: better handling
		// TODO: investigate why make_request returns OBJECT??
		self.emit('ready');
		self.emit('error', new Error('random error'));
		//
		//
	};
	
	req.onabort = function () {
		// TODO: better handling
		self.emit('ready');
		self.emit('error', new Error('aborted'));
		//
	};
	
	req.ontimed = function () { // BAD FUNCTION NAMING
		// TODO: better handling
		self.emit('ready');
		self.emit('error', new Error('time out'));
		//
	};
	
	req.onload = function (res) {
		self.statusCode = res.code;
		self.headers = parseHeaders(res);
		
		self.emit('ready');
		
		self._emitData(res);
		
		self.emit('end');
		self.emit('close');
	};
};

Response.prototype._emitData = function (res) {
    var respBody = this.getResponse(res);
	
	if (!respBody) {
		return;
	}
	
    if (respBody.toString().match(/ArrayBuffer/)) {
        this.emit('data', new Uint8Array(respBody, this.offset));
        this.offset = respBody.byteLength;
        return;
    }
    if (respBody.length > this.offset) {
        this.emit('data', respBody.slice(this.offset));
        this.offset = respBody.length;
    }
};

var isArray = Array.isArray || function (xs) {
    return Object.prototype.toString.call(xs) === '[object Array]';
};

{'fraction_non_alphanumeric': 0.16895213454075034, 'fraction_numerical': 0.0015523932729624838, 'mean_word_length': 3.1885157096424703, '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': '1948648', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1264, 'n_words': 266}