Skip to content

Instantly share code, notes, and snippets.

@brapse
Created September 14, 2010 03:10
Show Gist options
  • Select an option

  • Save brapse/578466 to your computer and use it in GitHub Desktop.

Select an option

Save brapse/578466 to your computer and use it in GitHub Desktop.
Crawl.prototype.start_local = function(directory) {
var that = this;
sys.debug('starting local: ' + directory);
fs.readdir(directory, function(err, files) {
if(err) throw err;
files.forEach(function(file) {
sys.debug('file: ' + file);
var filename = directory + '/' + file;
fs.open(filename, 'r', function(err, fd) {
if(err) throw err;
fs.stat(filename, function(err, stats) {
sys.debug('stats:' + sys.inspect(stats));
if(err) throw err;
fs.read(fd, stats.size, null, 'utf8', function(err, contents) {
sys.debug('contents:' + contents);
if(err) throw err;
that.emit('page', file, contents);
});
});
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment