'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);
				});
			}
		});
	});
};

@@ -415,15 +415,59 @@
 %7B%0A%09%09
+// send %60null%60 if is a directory%0A%09%09if (!
 fs.stat
+Sync
 (fil
@@ -475,49 +475,22 @@
 path
-, function (err, stats) %7B%0A%09%09%09if (err
+).isFile()
 ) %7B%0A
-%09
 %09%09%09r
@@ -501,49 +501,22 @@
 n re
-j(err
+s(null
 );%0A%09%09
-%09
 %7D%0A%0A
-%09%09%09if (stats.isFile()) %7B%0A%09%09
 %09%09fs
@@ -561,18 +561,16 @@
 a) %7B%0A%09%09%09
-%09%09
 if (err)
@@ -572,18 +572,16 @@
 (err) %7B%0A
-%09%09
 %09%09%09%09retu
@@ -596,23 +596,19 @@
 rr);%0A%09%09%09
-%09%09
 %7D%0A%0A
-%09%09
 %09%09%09retur
@@ -624,21 +624,8 @@
 a);%0A
-%09%09%09%09%7D);%0A%09%09%09%7D%0A
 %09%09%7D)

rework utils.read further, resolove to null for directory