Files
bower/lib/util/file-exists.js
2012-10-24 08:45:47 +01:00

26 lines
714 B
JavaScript

// ==========================================
// BOWER: file-exists.js
// ==========================================
// Copyright 2012 Twitter, Inc
// Licensed under The MIT License
// http://opensource.org/licenses/MIT
// ==========================================
var fs = require('fs');
// This module exposes a version of fs.exists and fs.existsSync with a correct behaviour
// See: https://github.com/joyent/node/pull/2603
module.exports = function (path, callback) {
fs.stat(path, function (error) {
callback(!error || error.code !== 'ENOENT');
});
};
module.exports.sync = function (path, callback) {
try {
return !!fs.statSync(path);
} catch (e) {
return e.code !== 'ENOENT';
}
};