1 | ;
|
2 | var fs = require('fs');
|
3 | var Promise = require('pinkie-promise');
|
4 |
|
5 | module.exports = function (fp) {
|
6 | var fn = typeof fs.access === 'function' ? fs.access : fs.stat;
|
7 |
|
8 | return new Promise(function (resolve) {
|
9 | fn(fp, function (err) {
|
10 | resolve(!err);
|
11 | });
|
12 | });
|
13 | };
|
14 |
|
15 | module.exports.sync = function (fp) {
|
16 | var fn = typeof fs.accessSync === 'function' ? fs.accessSync : fs.statSync;
|
17 |
|
18 | try {
|
19 | fn(fp);
|
20 | return true;
|
21 | } catch (err) {
|
22 | return false;
|
23 | }
|
24 | };
|