This package has been deprecated

Author message:

error and cancel events exposed in 1.4.0-0

wiostream

1.4.0-0 • Public • Published

wiostream

Stream filepaths from a directory tree

This is BETA.

Usage

var wiostream = require('wiostream');
 
/**
 * @param {string}    path      path to walk
 * @param {string}    encoding  optional encoding
 * @param {function}  control   optional descent controller
 *
 * @returns {function}  cancels walk then emits 
 *                      "cancel" event before "end"
 *                      If walk ends before cancelWalk()
 *                      is called "cancel" will not emitted.
 */
var stream = wiostream('.', 'utf8', controlDescent)
  .on('error', console.log.bind(null, 'got error:'))
  .on('cancel', console.log.bind(null, 'walk cancelled'))
  .on('end', console.log.bind(null, 'walk complete'))
  .on('data', console.log.bind(null, 'got filepath:'));
 
// stream.cancelWalk() is available
// to cancel walk then emit "cancel" event before "end"
// If walk ends before cancelWalk() is called then
// the "cancel" event will not emitted
 
// sample descent controller
function controlDescent(
    dirname, dirpath, descend, skip, depth) {
 
  var excludeDir = /^\.|node_modules/.test(dirname);
  var atMaxDepth = (depth === 2);
 
  // skip dot-directories and node_modules
  // and don't go more than 2 levels deep
  excludeDir || atMaxDepth ? skip() : descend();
}

Output:

got filepath: package.json
got filepath: index.js
got filepath: README.md
got filepath: .npmignore
got filepath: .gitignore
walk complete

Package Sidebar

Install

npm i wiostream

Weekly Downloads

12

Version

1.4.0-0

License

MIT

Last publish

Collaborators

  • ecman