"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x86/node_modules/npm/node_modules/duplexer3/README.md" (14 Feb 2020, 2822 Bytes) of package /windows/www/node-v12.18.4-win-x86.zip:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

duplexer3 Build Status Coverage Status

Like duplexer2 but using Streams3 without readable-stream dependency

var stream = require("stream");

var duplexer3 = require("duplexer3");

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() {
  }, 500);

var duplex = duplexer3(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.


Available via npm:

$ npm i duplexer3



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.

duplexer3([options], writable, readable)
const duplex = duplexer3(new stream.Writable(), new stream.Readable());




3-clause BSD. A copy is included with the source.