Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

duplexer2-unwrappable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duplexer2-unwrappable

Like duplexer2 but unwrappable

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

duplexer2-unwrappable

Build Status Coverage Status Dependency Status devDependency Status Downloads

Like duplexer2 but unwrappable

NPM

var stream = require("stream");

var duplexer2 = require("duplexer2-unwrappable");

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

Overview

This is a reimplementation of duplexer using the Streams3 API which is standard in Node as of v4. Everything largely works the same.

Installation

Available via npm:

$ npm i duplexer2-unwrappable

API

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. now exposed so you can unwrap streams and avoid having closures bind streams together forever.

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

Arguments

  • options - an object specifying the regular stream.Duplex options, as well as the properties described below.
  • writable - a writable stream
  • readable - a readable stream

Options

  • bubbleErrors - a boolean value that specifies whether to bubble errors from the underlying readable/writable streams. Default is true.

Instance Methods

  • unbind - unbinds the duplexer2 instance from the writable and readable stream methods, allowing the underlying streams to be re-used.

License

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

Contact

Keywords

FAQs

Package last updated on 28 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc