<commit_before>'use strict';

var debug = require('debug');
var _ = debug('fly:read');
var fs = require('fs');

/**
 * Read a file and return its normalized contents
 * @param {String}   filepath      The file at filepath to read
 * @return {Promise}   						 The Promise that will resolve to file's contents
 */
module.exports = function (filepath) {
	_('read this file: %f', filepath);

	return new Promise(function (res, rej) {
		fs.readFile(filepath, function (err, data) {
			if (err) {
				return rej(err);
			}

			return res(data);
		});
	});
};<commit_msg>utils.read will not read dirs & throw EISDIR<commit_after>'use strict';

var debug = require('debug');
var _ = debug('fly:read');
var fs = require('fs');

/**
 * Read a file and return its normalized contents
 * @param {String}   filepath      The file at filepath to read
 * @return {Promise}   						 The Promise that will resolve to file's contents
 */
module.exports = function (filepath) {
	_('read this file: %f', filepath);

	return new Promise(function (res, rej) {
		fs.stat(filepath, function (err, stats) {
			if (err) {
				return rej(err);
			}

			if (stats.isFile()) {
				fs.readFile(filepath, function (err, data) {
					if (err) {
						return rej(err);
					}

					return res(data);
				});
			}
		});
	});
};
{'fraction_non_alphanumeric': 0.14837712519319937, 'fraction_numerical': 0.0, 'mean_word_length': 3.1774193548387095, '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': '5728334', 'n_tokens_mistral': 483, 'n_tokens_neox': 418, 'n_words': 136}