Don't use a web worker for loading all paths

Instead use  fs.realpath() and fs.stat() to walk the project
tree asynchronously.
This commit is contained in:
Kevin Sawicki
2013-03-13 11:27:54 -07:00
parent 20e2f2bb7c
commit 8fe9e31c08
3 changed files with 54 additions and 34 deletions

View File

@@ -168,6 +168,33 @@ module.exports =
traverse(rootPath, '', onFile, onDirectory)
traverseTreeAsync: (rootPath, onFile, onDirectory, onDone) ->
pathCounter = 0
startPath = -> pathCounter++
endPath = -> onDone() if --pathCounter is 0
traverse = (rootPath, onFile, onDirectory) =>
startPath()
fs.readdir rootPath, (error, files) =>
if error or files.length is 0
endPath()
return
for file in files
path = @join(rootPath, file)
do (path) =>
startPath()
fs.stat path, (error, stats) =>
unless error
if stats.isFile()
onFile(path)
else if stats.isDirectory()
traverse(path, onFile, onDirectory) if onDirectory(path)
endPath()
endPath()
traverse(rootPath, onFile, onDirectory)
md5ForPath: (path) ->
contents = fs.readFileSync(path)
require('crypto').createHash('md5').update(contents).digest('hex')