├── .travis.yml ├── examples ├── no-devnull.js └── devnull.js ├── .gitignore ├── index.js ├── test ├── fixtures │ └── number-readable.js └── index.js ├── README.md ├── LICENSE └── package.json /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /examples/no-devnull.js: -------------------------------------------------------------------------------- 1 | var numbers = require('../test/fixtures/number-readable') 2 | 3 | numbers({ to: 3 }) 4 | .on('data', function (d) { console.log(d.toString()) }); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | -------------------------------------------------------------------------------- /examples/devnull.js: -------------------------------------------------------------------------------- 1 | var devnull = require('../'); 2 | var numbers = require('../test/fixtures/number-readable'); 3 | 4 | numbers({ to: 3 }) 5 | .pipe(devnull()) 6 | .on('data', function (d) { console.log(d.toString()) }); 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util') 4 | , stream = require('stream') 5 | , Writable = stream.Writable 6 | , setImmediate = setImmediate || function (fn) { setTimeout(fn, 0) } 7 | ; 8 | 9 | module.exports = DevNull; 10 | 11 | util.inherits(DevNull, Writable); 12 | 13 | function DevNull (opts) { 14 | if (!(this instanceof DevNull)) return new DevNull(opts); 15 | 16 | opts = opts || {}; 17 | Writable.call(this, opts); 18 | } 19 | 20 | DevNull.prototype._write = function (chunk, encoding, cb) { 21 | setImmediate(cb); 22 | } 23 | -------------------------------------------------------------------------------- /test/fixtures/number-readable.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util') 4 | , stream = require('stream') 5 | , Readable = stream.Readable 6 | 7 | module.exports = NumberReadable; 8 | 9 | util.inherits(NumberReadable, Readable); 10 | 11 | function NumberReadable (opts) { 12 | if (!(this instanceof NumberReadable)) return new NumberReadable(opts); 13 | Readable.call(this, opts); 14 | this.idx = 0; 15 | this.to = opts.to; 16 | } 17 | 18 | NumberReadable.prototype._read = function () { 19 | if (this.idx > this.to) return this.push(null); 20 | this.push('' + this.idx++); 21 | } 22 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /*jshint asi: true */ 3 | 4 | var test = require('tap').test 5 | var devnull = require('../'); 6 | var tapstream = require('tap-stream') 7 | var numbers = require('./fixtures/number-readable') 8 | 9 | test('\npiping without devnull', function (t) { 10 | var data = []; 11 | numbers({ to: 2 }) 12 | .on('data', function (d) { data.push(d) }) 13 | .on('end', function () { 14 | t.equal(data.length, 3, 'streams 3 numbers') 15 | t.end() 16 | }) 17 | }) 18 | 19 | test('\npiping through devnull', function (t) { 20 | var data = []; 21 | numbers({ to: 2 }) 22 | .on('end', function () { 23 | t.equal(data.length, 0, 'streams 0 numbers') 24 | t.end() 25 | }) 26 | .pipe(devnull()) 27 | .on('data', function (d) { data.push(d) }) 28 | }) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dev-null [![build status](https://secure.travis-ci.org/thlorenz/dev-null.png)](http://travis-ci.org/thlorenz/dev-null) 2 | 3 | `/dev/null` for node streams 4 | 5 | Use it whenever you need to interrupt stream flow for instance if you want to log the state of a stream instead of its 6 | output. 7 | 8 | ```js 9 | // without devnull 10 | var numbers = require('../test/fixtures/number-readable') 11 | 12 | numbers({ to: 2 }) 13 | .on('data', function (d) { console.log(d.toString()) }); 14 | // => 15 | // 0 16 | // 1 17 | // 2 18 | ``` 19 | 20 | ```js 21 | // piping into devnull 22 | var devnull = require('dev-null'); 23 | var numbers = require('../test/fixtures/number-readable'); 24 | 25 | numbers({ to: 2 }) 26 | .pipe(devnull()) 27 | .on('data', function (d) { console.log(d.toString()) }); 28 | 29 | // => (no output) 30 | ``` 31 | 32 | ## Installation 33 | 34 | npm install dev-null 35 | 36 | ## License 37 | 38 | MIT 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 Thorsten Lorenz. 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-null", 3 | "version": "0.1.1", 4 | "description": "/dev/null for node streams", 5 | "main": "index.js", 6 | "scripts": { 7 | "test-main": "tap test/*.js", 8 | "test-0.10": "nave use 0.10 npm run test-main", 9 | "test-all": "npm run test-main && npm run test-0.10", 10 | "test": "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com/thlorenz/dev-null.git" 15 | }, 16 | "homepage": "https://github.com/thlorenz/dev-null", 17 | "dependencies": {}, 18 | "devDependencies": { 19 | "nave": "~0.4.3", 20 | "tap": "~0.4.3", 21 | "tap-stream": "~0.2.0" 22 | }, 23 | "keywords": [ 24 | "streams", 25 | "test", 26 | "debug", 27 | "ignore", 28 | "silence" 29 | ], 30 | "author": { 31 | "name": "Thorsten Lorenz", 32 | "email": "thlorenz@gmx.de", 33 | "url": "http://thlorenz.com" 34 | }, 35 | "license": { 36 | "type": "MIT", 37 | "url": "https://github.com/thlorenz/dev-null/blob/master/LICENSE" 38 | }, 39 | "engine": { 40 | "node": ">=0.10" 41 | } 42 | } 43 | --------------------------------------------------------------------------------