duplexer2
Advanced tools
Weekly downloads
Readme
Like duplexer but using Streams3
var stream = require("stream");
var duplexer2 = require("duplexer2");
var writable = new stream.Writable({objectMode: true}),
readable = new stream.Readable({objectMode: true});
writable._write = function _write(input, encoding, done) {
if (readable.push(input)) {
return done();
} else {
readable.once("drain", done);
}
};
readable._read = function _read(n) {
// no-op
};
// simulate the readable thing closing after a bit
writable.once("finish", function() {
setTimeout(function() {
readable.push(null);
}, 500);
});
var duplex = duplexer2(writable, readable);
duplex.on("data", function(e) {
console.log("got data", JSON.stringify(e));
});
duplex.on("finish", function() {
console.log("got finish event");
});
duplex.on("end", function() {
console.log("got end event");
});
duplex.write("oh, hi there", function() {
console.log("finished writing");
});
duplex.end(function() {
console.log("finished ending");
});
got data "oh, hi there"
finished writing
got finish event
finished ending
got end event
This is a reimplementation of duplexer using the Streams3 API which is standard in Node as of v4. Everything largely works the same.
$ npm i duplexer2
Creates a new DuplexWrapper
object, which is the actual class that implements
most of the fun stuff. All that fun stuff is hidden. DON'T LOOK.
duplexer2([options], writable, readable)
const duplex = duplexer2(new stream.Writable(), new stream.Readable());
Arguments
stream.Duplex
options, as
well as the properties described below.Options
true
.3-clause BSD. A copy is included with the source.
Like duplexer but using streams3
The npm package duplexer2 receives a total of 7,013,684 weekly downloads. As such, duplexer2 popularity was classified as popular.
We found that duplexer2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 3 open source maintainers collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.