1 | var fs = require('fs')
|
2 | , path = require('path');
|
3 |
|
4 | exports.mstat = function (dir, files, callback) {
|
5 | (function mstat(files, stats) {
|
6 | var file = files.shift();
|
7 |
|
8 | if (file) {
|
9 | fs.stat(path.join(dir, file), function (e, stat) {
|
10 | if (e) {
|
11 | callback(e);
|
12 | } else {
|
13 | mstat(files, stats.concat([stat]));
|
14 | }
|
15 | });
|
16 | } else {
|
17 | callback(null, {
|
18 | size: stats.reduce(function (total, stat) {
|
19 | return total + stat.size;
|
20 | }, 0),
|
21 | mtime: stats.reduce(function (latest, stat) {
|
22 | return latest > stat.mtime ? latest : stat.mtime;
|
23 | }, 0),
|
24 | ino: stats.reduce(function (total, stat) {
|
25 | return total + stat.ino;
|
26 | }, 0)
|
27 | });
|
28 | }
|
29 | })(files.slice(0), []);
|
30 | };
|