Debian Codegraph @

fs2/stat.js

raw
1 "use strict";
2
3 var isCallable = require("es5-ext/object/is-callable")
4 , isValue = require("es5-ext/object/is-value")
5 , deferred = require("deferred")
6 , resolve = require("path").resolve
7 , original = require("fs").stat;
8
9 var stat = function (path, options) {
10 var def = deferred();
11 original(path, function (err, stats) {
12 if (err) {
13 if (options.loose && err.code === "ENOENT") def.resolve(null);
14 else def.reject(err);
15 } else {
16 def.resolve(stats);
17 }
18 });
19 return def.promise;
20 };
21 stat.returnsPromise = true;
22
23 module.exports = function (path/*, callback*/) {
24 var options, cb;
25
26 path = resolve(String(path));
27 options = arguments[1];
28 cb = arguments[2];
29 if (!isValue(cb) && isCallable(options)) {
30 cb = options;
31 options = {};
32 } else {
33 options = Object(options);
34 }
35
36 return stat(path, options).cb(cb);
37 };
38 module.exports.returnsPromise = true;
39 module.exports.stat = stat;