<commit_before>node-walk
====

nodejs walk implementation.

This is somewhat of a port python's `os.walk`, but using Node.JS conventions.

  * EventEmitter
  * Asynchronous
  * Chronological (optionally)
  * Built-in flow-control
  * includes Synchronous version (same API as Asynchronous)

As few file descriptors are opened at a time as possible.
This is particularly well suited for single hard disks which are not flash or solid state.

Installation
----

    npm install walk

Usage
====

Both Asynchronous and Synchronous versions are provided.

The Synchronous version still uses callbacks, so it is safe to use with other Asynchronous functions and will still work as expected.

    var walk = require('walk'),
      fs = require('fs'),
      options,
      walker;

    options = {
        followLinks: false,
    };

    walker = walk.walk("/tmp", options);

    // OR
    // walker = walk.walkSync("/tmp", options);

    walker.on("names", function (root, nodeNamesArray) {
      nodeNames.sort(function (a, b) {
        if (a > b) return 1;
        if (a < b) return -1;
        return 0;
      });
    });

    walker.on("directories", function (root, dirStatsArray, next) {
      // dirStatsArray is an array of `stat` objects with the additional attributes
      // * type
      // * error
      // * name
      
      next();
    });

    walker.on("file", function (root, fileStats, next) {
      fs.readFile(fileStats.name, function () {
        // doStuff
        next();
      });
    });

    walker.on("errors", function (root, nodeStatsArray, next) {
      next();
    });

    walker.on("end", function () {
      console.log("all done");
    });

API
====

Emitted Values

  * `on('XYZ', function(root, stats, next) {})`<commit_msg>make a more synchronous version possible<commit_after>node-walk
====

nodejs walk implementation.

This is somewhat of a port python's `os.walk`, but using Node.JS conventions.

  * EventEmitter
  * Asynchronous
  * Chronological (optionally)
  * Built-in flow-control
  * includes Synchronous version (same API as Asynchronous)

As few file descriptors are opened at a time as possible.
This is particularly well suited for single hard disks which are not flash or solid state.

Installation
----

    npm install walk

Usage
====

Both Asynchronous and Synchronous versions are provided.

var walk = require('walk')
  , fs = require('fs')
  , options
  , walker
  ;

options = {
    followLinks: false,
};

walker = walk.walk("/tmp", options);

// OR
// walker = walk.walkSync("/tmp", options);

walker.on("names", function (root, nodeNamesArray) {
  nodeNames.sort(function (a, b) {
    if (a > b) return 1;
    if (a < b) return -1;
    return 0;
  });
});

walker.on("directories", function (root, dirStatsArray, next) {
  // dirStatsArray is an array of `stat` objects with the additional attributes
  // * type
  // * error
  // * name
  
  next();
});

walker.on("file", function (root, fileStats, next) {
  fs.readFile(fileStats.name, function () {
    // doStuff
    next();
  });
});

walker.on("errors", function (root, nodeStatsArray, next) {
  next();
});

walker.on("end", function () {
  console.log("all done");
});
```
### Async

The Synchronous version can operate without a callback if the event handlers are passed in

```javascript
var walk = require('walk')
  , fs = require('fs')
  , options
  , walker
  ;

options = {
    listeners: {
        names: function (root, nodeNamesArray) {
          nodeNames.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
            next();
          });
        }
      , errors: function (root, nodeStatsArray, next) {
          next();
        }
    }
};

walker = walk.walkSync("/tmp", options);

console.log("all done");
```

API
====

Emitted Values

  * `on('XYZ', function(root, stats, next) {})`
{'fraction_non_alphanumeric': 0.1334735857877513, 'fraction_numerical': 0.0021037868162692847, 'mean_word_length': 2.470397404703974, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6998273', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1271, 'n_words': 412}