[Pkg-javascript-commits] [node-static] 17/151: mstat: multiple file stat utility

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:17:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository node-static.

commit 64aca802a0f81bec2cb3f2e12407ddede236d2db
Author: cloudhead <self at cloudhead.net>
Date:   Tue Aug 3 17:13:33 2010 -0400

    mstat: multiple file stat utility
---
 lib/node-static.js      |  1 +
 lib/node-static/util.js | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/lib/node-static.js b/lib/node-static.js
index 116279c..bc38a85 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -9,6 +9,7 @@ var fs = require('fs'),
 this.version = [0, 3, 1];
 
 var mime = require('./node-static/mime');
+var util = require('./node-static/util');
 
 var serverInfo = 'node-static/' + this.version.join('.');
 
diff --git a/lib/node-static/util.js b/lib/node-static/util.js
new file mode 100644
index 0000000..067a6ee
--- /dev/null
+++ b/lib/node-static/util.js
@@ -0,0 +1,30 @@
+var fs = require('fs'),
+    path = require('path');
+
+this.mstat = function (dir, files, callback) {
+    (function mstat(files, stats) {
+        var file = files.shift();
+
+        if (file) {
+            fs.stat(path.join(dir, file), function (e, stat) {
+                if (e) {
+                    callback(e);
+                } else {
+                    mstat(files, stats.concat([stat]));
+                }
+            });
+        } else {
+            callback(null, {
+                size: stats.reduce(function (total, stat) {
+                    return total + stat.size;
+                }, 0),
+                mtime: stats.reduce(function (latest, stat) {
+                    return latest.mtime > stat.mtime ? latest.mtime : stat.mtime;
+                }, 0),
+                ino: stats.reduce(function (total, stat) {
+                    return total + stat.ino;
+                }, 0)
+            });
+        }
+    })(files.slice(0), []);
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git



More information about the Pkg-javascript-commits mailing list