fixed path type, added 'end', tested chronologability

This commit is contained in:
AJ ONeal 2010-12-12 02:13:40 -07:00
parent e68088526e
commit 1ca2e7ace3
5 changed files with 56 additions and 6 deletions

View File

@ -52,6 +52,10 @@ Usage
next(); next();
}); });
walker.on("end", function () {
console.log("all done");
});
API API
==== ====
@ -66,6 +70,8 @@ Emitted Values
Single Events - fired immediately Single Events - fired immediately
* `end` - No files, dirs, etc left to inspect
* `directoryError` - Error when `fstat` succeeded, but reading path failed (Probably due to permissions). * `directoryError` - Error when `fstat` succeeded, but reading path failed (Probably due to permissions).
* `node` - a `stats` object for a node of any type * `node` - a `stats` object for a node of any type
* `file` - includes links when `followLinks` is `true` * `file` - includes links when `followLinks` is `true`

View File

@ -0,0 +1,33 @@
(function () {
var walk = require("../lib/walk.js"),
emit = walk(process.argv[2] || "/tmp"),
util = require('util'),
path = require('path');
// nor the root, nor the node should ever be empty
walk.fnodeTypesPlural.forEach(function (fnodeType) {
emit.on(fnodeType, function (root, nodes, next) {
if (!nodes || !nodes.length || !root) {
console.log(fnodeType, "empty set", root, nodes.length); //JSON.stringify(nodes));
}
next();
});
});
walk.fnodeTypes.forEach(function (fnodeType) {
emit.on(fnodeType, function (root, node, next) {
if (!node || !node.name || !root) {
console.log(fnodeType, "empty item", root, node.name); //JSON.stringify(node));
}
next();
});
});
emit.on('directory', function (root, dir, next) {
console.log(path.join(root, dir.name));
setTimeout(next, 100);
});
emit.on('file', function (root, file, next) {
console.log(path.join(root, file.name));
setTimeout(next, 100);
});
}());

View File

@ -1,5 +1,5 @@
(function () { (function () {
var walk = require("../lib/walk3.js"), var walk = require("../lib/walk.js"),
emit = walk(process.argv[2] || "/tmp"), emit = walk(process.argv[2] || "/tmp"),
util = require('util'), util = require('util'),
path = require('path'); path = require('path');
@ -31,5 +31,8 @@
next(); next();
}); });
*/ */
emit.on('end', function () {
console.log("All Done!");
});
}()); }());

View File

@ -1,5 +1,5 @@
(function () { (function () {
var walk = require("../lib/walk3.js"), var walk = require("../lib/walk.js"),
emit = walk(process.argv[2] || "/tmp"); emit = walk(process.argv[2] || "/tmp");
//icount = 0; //icount = 0;

View File

@ -20,8 +20,16 @@
"files", "directories", "blockDevices", "characterDevices", "symbolicLinks", "FIFOs", "sockets" "files", "directories", "blockDevices", "characterDevices", "symbolicLinks", "FIFOs", "sockets"
]; ];
function newVersion() {
throw new Error("New Version. Please see API on github.com/coolaj86/node-walk");
}
// Create a new walk instance // Create a new walk instance
function create(path, options) { function create(path, options, cb) {
if (cb) {
newVersion();
}
var emitter = new events.EventEmitter(), var emitter = new events.EventEmitter(),
fstat = (options||{}).followLinks ? fs.stat : fs.lstat; fstat = (options||{}).followLinks ? fs.stat : fs.lstat;
@ -103,7 +111,6 @@
} }
fstat(upath.join(path, file), function (err, stats) { fstat(upath.join(path, file), function (err, stats) {
//console.log("`stat`ed file " + file);
stats = stats || {}; stats = stats || {};
stats.name = file; stats.name = file;
nodeGroups.nodes.push(stats); nodeGroups.nodes.push(stats);
@ -145,9 +152,10 @@
} }
walk(upath.normalize(path), function () { walk(upath.normalize(path), function () {
//throw Error("hey"); emitter.emit('end');
//console.log("Utterly Done!");
}); });
emitter.walk = newVersion;
emitter.whenever = newVersion;
return emitter; return emitter;
} }
module.exports = create; module.exports = create;