-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds simplified constructor pattern, allowing users to provide "read", "write", "transform", "flush", and "writev" functions as stream options in lieu of subclassing. Semver: minor PR-URL: #697 Fixes: nodejs/readable-stream#102 Reviewed-By: Chris Dickinson <[email protected]>
- Loading branch information
1 parent
e0730ee
commit 50daee7
Showing
7 changed files
with
175 additions
and
2 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
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
18 changes: 18 additions & 0 deletions
18
test/parallel/test-stream-readable-constructor-set-methods.js
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,18 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Readable = require('stream').Readable; | ||
|
||
var _readCalled = false; | ||
function _read(n) { | ||
_readCalled = true; | ||
this.push(null); | ||
} | ||
|
||
var r = new Readable({ read: _read }); | ||
r.resume(); | ||
|
||
process.on('exit', function () { | ||
assert.equal(r._read, _read); | ||
assert(_readCalled); | ||
}); |
31 changes: 31 additions & 0 deletions
31
test/parallel/test-stream-transform-constructor-set-methods.js
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,31 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Transform = require('stream').Transform; | ||
|
||
var _transformCalled = false; | ||
function _transform(d, e, n) { | ||
_transformCalled = true; | ||
n(); | ||
} | ||
|
||
var _flushCalled = false; | ||
function _flush(n) { | ||
_flushCalled = true; | ||
n(); | ||
} | ||
|
||
var t = new Transform({ | ||
transform: _transform, | ||
flush: _flush | ||
}); | ||
|
||
t.end(new Buffer('blerg')); | ||
t.resume(); | ||
|
||
process.on('exit', function () { | ||
assert.equal(t._transform, _transform); | ||
assert.equal(t._flush, _flush); | ||
assert(_transformCalled); | ||
assert(_flushCalled); | ||
}); |
34 changes: 34 additions & 0 deletions
34
test/parallel/test-stream-writable-constructor-set-methods.js
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,34 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Writable = require('stream').Writable; | ||
|
||
var _writeCalled = false; | ||
function _write(d, e, n) { | ||
_writeCalled = true; | ||
} | ||
|
||
var w = new Writable({ write: _write }); | ||
w.end(new Buffer('blerg')); | ||
|
||
var _writevCalled = false; | ||
var dLength = 0; | ||
function _writev(d, n) { | ||
dLength = d.length; | ||
_writevCalled = true; | ||
} | ||
|
||
var w2 = new Writable({ writev: _writev }); | ||
w2.cork(); | ||
|
||
w2.write(new Buffer('blerg')); | ||
w2.write(new Buffer('blerg')); | ||
w2.end(); | ||
|
||
process.on('exit', function () { | ||
assert.equal(w._write, _write); | ||
assert(_writeCalled); | ||
assert.equal(w2._writev, _writev); | ||
assert.equal(dLength, 2); | ||
assert(_writevCalled); | ||
}); |