function makeExamplePipe() { return es.pipe( es.map(function (data, callback) { callback(null, data * 2) }), es.map(function (data, callback) { d.delay(callback)(null, data) }), es.map(function (data, callback) { callback(null, data + 2) })) }
Redis.prototype.stream = function (cmd, key, curry /* moar? */) { var curry = Array.prototype.slice.call(arguments) , clip = 1 , _redis = this.createConnection() , stream = es.pipe( es.pipe( es.map(function (data, fn) { var elems = [].concat(stream.curry) , str = data+'' if (!str.length) return fn() else elems.push(str) // console.log('write', str) return Redis.parse(elems, fn) }), _redis ), es.pipe( es.split('\r\n'), es.map(replyParser) ) ) ; stream.curry = curry stream.redis = _redis stream.redis.write(Redis.parse([ 'select', this.db ])) return stream function replyParser (data, fn) { if (Redis.debug_mode) console.log('replyParser', data+'') var str = (data+'').replace(replace1, '').replace(replace2, '') if (!str.length) return fn() else if (clip) { clip-- return fn() } else return fn(null, str) } }
(function(process) { var inspect = require('util').inspect; if (!module.parent) { var map = require('../index'); var es = require('event-stream'); es.pipe(process.openStdin(), es.split(), map(function(data, callback) { var j; try { j = JSON.parse(data); } catch (err) { return callback(null, data); } callback(null, inspect(j)); }), process.stdout); } })(require('process'));
exports['read array then map'] = function (test) { var readThis = d.map(3, 6, 100, d.id) //array of multiples of 3 < 100 , first = es.readArray(readThis) , read = [] , pipe = es.pipe( first, es.map(function (data, callback) { callback(null, {data: data}) }), es.map(function (data, callback) { callback(null, {data: data}) }), es.writeArray(function (err, array) { it(array).deepEqual(d.map(readThis, function (data) { return {data: {data: data}} })) test.done() }) ) }
var inspect = require('util').inspect var es = require('event-stream') //load event-stream var split = require('../') if(!module.parent) { es.pipe( //pipe joins streams together process.openStdin(), //open stdin split(), //split stream to break on newlines es.map(function (data, callback) {//turn this async function into a stream var j try { j = JSON.parse(data) //try to parse input into json } catch (err) { return callback(null, data) //if it fails just pass it anyway } callback(null, inspect(j)) //render it nicely }), process.stdout // pipe it to stdout ! ) } // run this // // curl -sS registry.npmjs.org/event-stream | node pretty.js //
lint = function (err) { var myRet; // prepare for linting exports src.jslint = {}; if (err || !JSLINT) { myRet = fn(err || 'gulp-jslint: failed to load JSLINT.'); } else { // convert to string js = src.contents.toString('utf8'); // lint the file src.jslint.edition = JSLINT.edition; src.jslint.success = JSLINT(js, options); src.jslint.errors = JSLINT.errors; // reporter handling if (!src.jslint.success) { if (options.reporter === 'default') { error = '[FAIL] ' + src.path.replace(path.resolve(__dirname) + '/', ''); for (i = 0; i < JSLINT.errors.length; i += 1) { if (JSLINT.errors[i]) { error += '\n line ' + JSLINT.errors[i].line + ', col ' + JSLINT.errors[i].character + ': ' + JSLINT.errors[i].reason; } } console.log('%s', error.red); } else { try { // grab the reporter options.reporter = require(options.reporter); // do the piping evtStr.pipe(options.reporter); } catch (err_a) { console.log(('error: unknown reporter: ' + options.reporter).red); } } fn('gulp-jslint: failed to lint file.'); } else { if (options.reporter === 'default') { if (options.errorsOnly !== true) { console.log('[%s] %s', 'PASS'.green, src.path.replace(path.resolve(__dirname) + '/', '').cyan); } } else { try { // grab the reporter options.reporter = require(options.reporter); // do the piping evtStr.pipe(options.reporter); } catch (err_b) { console.log(('error: unknown reporter: ' + options.reporter).red); } } myRet = fn(null, src); } } return myRet; };