MCPcopy
hub / github.com/yortus/asyncawait / getAllPathsAndStats

Function getAllPathsAndStats

comparison/largest/largest-callbacks.js:22–50  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

20
21 // Enumerate all files and subfolders in 'dir' to get their stats.
22 function getAllPathsAndStats(callback) {
23 fs.readdir(dir, function (err, files) {
24 if (err) { callback(err); return; }
25 var paths = _.map(files, function (file) { return path.join(dir, file); });
26 var stats = [];
27 var remaining = paths.length;
28 if (remaining === 0) {
29
30 // Directory is empty.
31 callback(null, { paths: paths, stats: stats });
32 } else {
33
34 // Get all file stats in parallel.
35 paths.forEach(function (path, i) {
36 fs.stat(path, function (err, stat) {
37 if (remaining === 0) return;
38 if (err) {
39 remaining = 0;
40 callback(err);
41 } else {
42 stats[i] = stat;
43 --remaining;
44 if (remaining === 0) callback(null, { paths: paths, stats: stats });
45 }
46 });
47 });
48 }
49 });
50 }
51
52 // Build up a list of possible candidates, recursing into subfolders if requested.
53 function listCandidates(paths, stats, callback) {

Callers 1

largestFunction · 0.85

Calls 4

joinMethod · 0.80
mapMethod · 0.65
forEachMethod · 0.65
callbackFunction · 0.50

Tested by

no test coverage detected