2022-01-21 08:28:41 +00:00
|
|
|
'use strict';
|
2022-05-29 09:24:36 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var Promise = require('pinkie-promise');
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
module.exports = function (fp) {
|
|
|
|
var fn = typeof fs.access === 'function' ? fs.access : fs.stat;
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
fn(fp, function (err) {
|
|
|
|
resolve(!err);
|
|
|
|
});
|
|
|
|
});
|
2022-01-21 08:28:41 +00:00
|
|
|
};
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
module.exports.sync = function (fp) {
|
|
|
|
var fn = typeof fs.accessSync === 'function' ? fs.accessSync : fs.statSync;
|
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
try {
|
2022-05-29 09:24:36 +00:00
|
|
|
fn(fp);
|
2022-01-21 08:28:41 +00:00
|
|
|
return true;
|
2022-05-29 09:24:36 +00:00
|
|
|
} catch (err) {
|
2022-01-21 08:28:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|