fs-walk.js/test/testSync.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2011-05-03 03:11:03 +00:00
(function () {
"use strict";
2013-06-23 06:19:24 +00:00
var walk = require('../lib/walk')
2011-05-03 03:11:03 +00:00
, fs = require('fs')
2013-06-23 05:58:50 +00:00
, options
, walker
;
options = {
listeners: {
names: function (root, nodeNamesArray) {
nodeNamesArray.sort(function (a, b) {
if (a > b) return 1;
if (a < b) return -1;
return 0;
});
}
, directories: function (root, dirStatsArray, next) {
// dirStatsArray is an array of `stat` objects with the additional attributes
// * type
// * error
// * name
next();
}
, file: function (root, fileStats, next) {
fs.readFile(fileStats.name, function () {
// doStuff
console.log(root, fileStats.name);
next();
});
}
, errors: function (root, nodeStatsArray, next) {
next();
}
}
};
walker = walk.walkSync("/tmp", options);
console.log("all done");
2011-05-03 03:11:03 +00:00
}());