forked from voltrue2/in-app-purchase
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutil.js
43 lines (40 loc) · 1.2 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const fs = require('fs');
module.exports.walkDir = function __libWalkDir(path, cb) {
var res = [];
var pending = 0;
var eachWalk = function __libEachWalk(error, results) {
if (error) {
return cb(error);
}
res = res.concat(results);
pending--;
if (!pending) {
return cb(null, res);
}
};
fs.lstat(path, function __libWalkOnStat(error, stat) {
if (error) {
return cb(error);
}
if (!stat.isDirectory()) {
res.push({ file: path, stat: stat });
return cb(null, res);
}
fs.readdir(path, function __libWalkOnReaddir(error, list) {
if (error) {
return cb(error);
}
pending += list.length;
if (!pending) {
return cb(null, res);
}
for (var i = 0, len = list.length; i < len; i++) {
var file = list[i];
var slash = path.substring(path.length - 1) !== '/' ? '/' : '';
var filePath = path + slash + file;
module.exports.walkDir(filePath, eachWalk);
}
});
});
};