mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-04-23 16:14:52 +00:00
1 line
No EOL
983 B
JavaScript
1 line
No EOL
983 B
JavaScript
var crawlerFactory=function(a,b,c,d){var e=function(){a.bindAll(this)};return e.prototype.crawl=function(a,d){var e=this,f=[],g=function(a,b){e.onComplete(a,b,f,d)};a&&a!==""?(a=c.resolve(a),b.readdir(a,g)):d(f)},e.prototype.classifyHandle=function(a,c){b.stat(a,function(b,d){b?c({file:a,err:b}):c({file:a,isDirectory:d.isDirectory()})})},e.prototype.classifyHandles=function(a,b){var c=this;a&&a.length>0?d.parallel(a,this.classifyHandle,function(a){c.onClassified(a,b)}):b([],[])},e.prototype.onClassified=function(a,b){var c=[],d=[],e;for(e in a)e.isDirectory?d.push(e.file):e.error||c.push(e.file);b(c,d)},e.prototype.onContents=function(a,b,d,e){var f=this,g=[],h=function(a,b){f.onQualified(a,b,d,e)},i;if(!err&&b.length>0){for(i in b)g.push(c.resolve(directory,i));this.classifyHandles(g,h)}else e(d)},e.prototype.onQualified=function(b,c,e,f){e=e.concat(b),c.length>0?d.parallel(c,this.crawl,function(b){e=e.concat(a.flatten(b)),f(e)}):f(e)},e};module.exports=crawlerFactory |