Closed bwin closed 9 years ago
its asynchronous so the only way to make it deterministic is to wait for the end event and put the file paths into a sorted list.
something like this should work.
function deterministic(dir,cb){
var bs = require('binarysearch');
var walkdir = require('walkdir');
var sorted = [];
var emitter = walkdir(dir);
walkdir.on('path',function(p){
bs.insert(sorted,p);
}).on('end',function(){
cb(false,sorted);
}).on('error',function(err){
cb(err);
});
}
perhaps this can be the default for the callback mode
Misread your comment and didn't look at the code (was on mobile). Described your approach wrong in my comment (see referenced above). Corrected now. Sorry.
so. do you think i should make the files array callback with a sorted list? i guess you aren't using it anymore but ill close this unless you have anything to add
In my latest code I use it. I tested
binarysearch
-version (with an additional hash to hold stats)The last one slightly outperformed the binarysearch
-version, so I chose the simple solution. There is virtually no performance hit in my test cases.
Thanks for participating.
so. do you think i should make the files array callback with a sorted list?
No. Because anyone can easily do result.sort()
.
perfect
Forgot to mention, I also tested
walkdir.sync(src, function(file, stat) {...
glob
with {sync: true}
glob
with manual fs.lstat
callsBTW the sort version was also faster than walkdir.sync
in my test cases. Glob was the slowest.
The order of the files emitted isn't constant. Is there a way to have a fixed order (=sorting)?