-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
141 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var devnull = require('../'); | ||
var numbers = require('../test/fixtures/number-readable'); | ||
|
||
numbers({ to: 3 }) | ||
.pipe(devnull()) | ||
.on('data', function (d) { console.log(d.toString()) }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var numbers = require('../test/fixtures/number-readable') | ||
|
||
numbers({ to: 3 }) | ||
.on('data', function (d) { console.log(d.toString()) }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
var util = require('util') | ||
, stream = require('stream') | ||
, Writable = stream.Writable | ||
, setImmediate = setImmediate || function (fn) { setTimeout(fn, 0) } | ||
; | ||
|
||
module.exports = DevNull; | ||
|
||
util.inherits(DevNull, Writable); | ||
|
||
function DevNull (opts) { | ||
if (!(this instanceof DevNull)) return new DevNull(opts); | ||
|
||
opts = opts || {}; | ||
Writable.call(this, opts); | ||
} | ||
|
||
DevNull.prototype._write = function (chunk, encoding, cb) { | ||
setImmediate(cb); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
{ | ||
"name" : "dev-null-writable", | ||
"version" : "0.0.0", | ||
"description" : "/dev/null for node streams", | ||
"main" : "index.js", | ||
"scripts" : { | ||
"test-main" : "tap test/*.js", | ||
"test-0.8" : "nave use 0.8 npm run test-main", | ||
"test-0.10" : "nave use 0.10 npm run test-main", | ||
"test-all": "npm run test-main && npm run test-0.8 && npm run test-0.10", | ||
"test" : "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi" | ||
}, | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "git://github.com/thlorenz/dev-null-writable.git" | ||
}, | ||
"homepage" : "https://github.com/thlorenz/dev-null-writable", | ||
"dependencies" : { | ||
}, | ||
"devDependencies" : { | ||
"nave": "~0.4.3", | ||
"tape": "~1.0.4", | ||
"tap": "~0.4.3" | ||
}, | ||
"keywords": [] , | ||
"author" : { | ||
"name" : "Thorsten Lorenz", | ||
"email" : "thlorenz@gmx.de", | ||
"url" : "http://thlorenz.com" | ||
}, | ||
"license" : { | ||
"type": "MIT", | ||
"url": "https://github.com/thlorenz/dev-null-writable/blob/master/LICENSE" | ||
}, | ||
"engine" : { "node" : ">=0.6" } | ||
"name": "dev-null", | ||
"version": "0.0.0", | ||
"description": "/dev/null for node streams", | ||
"main": "index.js", | ||
"scripts": { | ||
"test-main": "tap test/*.js", | ||
"test-0.8": "nave use 0.8 npm run test-main", | ||
"test-0.10": "nave use 0.10 npm run test-main", | ||
"test-all": "npm run test-main && npm run test-0.8 && npm run test-0.10", | ||
"test": "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/thlorenz/dev-null.git" | ||
}, | ||
"homepage": "https://github.com/thlorenz/dev-null", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"nave": "~0.4.3", | ||
"tap": "~0.4.3", | ||
"tap-stream": "~0.2.0" | ||
}, | ||
"keywords": [], | ||
"author": { | ||
"name": "Thorsten Lorenz", | ||
"email": "thlorenz@gmx.de", | ||
"url": "http://thlorenz.com" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/thlorenz/dev-null/blob/master/LICENSE" | ||
}, | ||
"engine": { | ||
"node": ">=0.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var util = require('util') | ||
, stream = require('stream') | ||
, Readable = stream.Readable | ||
|
||
module.exports = NumberReadable; | ||
|
||
util.inherits(NumberReadable, Readable); | ||
|
||
function NumberReadable (opts) { | ||
if (!(this instanceof NumberReadable)) return new NumberReadable(opts); | ||
Readable.call(this, opts); | ||
this.idx = 0; | ||
this.to = opts.to; | ||
} | ||
|
||
NumberReadable.prototype._read = function () { | ||
if (this.idx > this.to) return this.push(null); | ||
this.push('' + this.idx++); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
/*jshint asi: true */ | ||
|
||
var test = require('tap').test | ||
var devnull = require('../'); | ||
var tapstream = require('tap-stream') | ||
var numbers = require('./fixtures/number-readable') | ||
|
||
test('\npiping without devnull', function (t) { | ||
var data = []; | ||
numbers({ to: 2 }) | ||
.on('data', function (d) { data.push(d) }) | ||
.on('end', function () { | ||
t.equal(data.length, 3, 'streams 3 numbers') | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('\npiping through devnull', function (t) { | ||
var data = []; | ||
numbers({ to: 2 }) | ||
.on('end', function () { | ||
t.equal(data.length, 0, 'streams 0 numbers') | ||
t.end() | ||
}) | ||
.pipe(devnull()) | ||
.on('data', function (d) { data.push(d) }) | ||
}) |