fixed path type, added 'end', tested chronologability
This commit is contained in:
parent
e68088526e
commit
1ca2e7ace3
|
@ -52,6 +52,10 @@ Usage
|
|||
next();
|
||||
});
|
||||
|
||||
walker.on("end", function () {
|
||||
console.log("all done");
|
||||
});
|
||||
|
||||
API
|
||||
====
|
||||
|
||||
|
@ -66,6 +70,8 @@ Emitted Values
|
|||
|
||||
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).
|
||||
* `node` - a `stats` object for a node of any type
|
||||
* `file` - includes links when `followLinks` is `true`
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}());
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
(function () {
|
||||
var walk = require("../lib/walk3.js"),
|
||||
var walk = require("../lib/walk.js"),
|
||||
emit = walk(process.argv[2] || "/tmp"),
|
||||
util = require('util'),
|
||||
path = require('path');
|
||||
|
@ -31,5 +31,8 @@
|
|||
next();
|
||||
});
|
||||
*/
|
||||
emit.on('end', function () {
|
||||
console.log("All Done!");
|
||||
});
|
||||
}());
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function () {
|
||||
var walk = require("../lib/walk3.js"),
|
||||
var walk = require("../lib/walk.js"),
|
||||
emit = walk(process.argv[2] || "/tmp");
|
||||
//icount = 0;
|
||||
|
||||
|
|
16
lib/walk.js
16
lib/walk.js
|
@ -20,8 +20,16 @@
|
|||
"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
|
||||
function create(path, options) {
|
||||
function create(path, options, cb) {
|
||||
if (cb) {
|
||||
newVersion();
|
||||
}
|
||||
|
||||
var emitter = new events.EventEmitter(),
|
||||
fstat = (options||{}).followLinks ? fs.stat : fs.lstat;
|
||||
|
||||
|
@ -103,7 +111,6 @@
|
|||
}
|
||||
|
||||
fstat(upath.join(path, file), function (err, stats) {
|
||||
//console.log("`stat`ed file " + file);
|
||||
stats = stats || {};
|
||||
stats.name = file;
|
||||
nodeGroups.nodes.push(stats);
|
||||
|
@ -145,9 +152,10 @@
|
|||
}
|
||||
|
||||
walk(upath.normalize(path), function () {
|
||||
//throw Error("hey");
|
||||
//console.log("Utterly Done!");
|
||||
emitter.emit('end');
|
||||
});
|
||||
emitter.walk = newVersion;
|
||||
emitter.whenever = newVersion;
|
||||
return emitter;
|
||||
}
|
||||
module.exports = create;
|
||||
|
|
Loading…
Reference in New Issue