Transforms and other streaming helpers
A few stream helpers, built for Node.js 0.10+ streams ("Streams2").
npm install streaming
new Glob(pattern, options) inherits
new Filter(predicate) inherits
new Stringifier(replacer, space) inherits
new Parser() inherits
new Mapper(fn) inherits
new Queue(concurrency, worker) inherits
var streaming = require'streaming';varsetTimeoutvar json = JSONstringifytask;callbacknull jsonlength + ' after 1s\n';1000;;processstdinpipepipeJSONparsepipe5 lazy_workerpipeprocessstdout;
What used to be
Rechunker have been folder into this more generic, more flexible class.
new Splitter(split, opts) inherits
new Timeout(seconds, opts) inherits
new Walk(root) inherits
streaming.Walk will emit data that are
streaming.Walk.Node objects. A
Node has two fields,
.path, which is relative to the given
.stats, which is a
node.toString() will return
It recurses the filesystem structure depth-first. If the given
root is not a directory, it will only ever emit that file. Otherwise, if
root is a directory, it will be emitted as a data point (just like all other directories under
root as it comes to them). The directory entry itself will always immediately precede its children. The order of children is taken exactly as they produced by
fs.readdir, which seems to be undefined or maybe by creation date (newest first).
fs.Stats has helper functions
.isDirectory(), so we can print the paths only files (ignoring directories) like this:
var streaming = require'streaming';var walk = '/usr/local';walkon'error'console.error'error' err;if errcode == 'EACCES'// if the error is just "access denied", ignore both the error and the file.// call resume() to carry on as if nothing had happenedwalkresume;elseconsole.error'Critical error; not resuming.';;walkon'data'// just skip over directories:if nodestatsisFileconsole.lognodetoString;;
_writableState has a
Copyright 2013-2014 Christopher Brown. MIT Licensed.