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

duplexer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duplexer

Creates a duplex stream

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13M
decreased by-14.95%
Maintainers
1
Weekly downloads
 
Created

What is duplexer?

The `duplexer` npm package is a utility for creating a duplex (readable and writable) stream from two separate streams: a writable stream for writing to and a readable stream for reading from. This is particularly useful in scenarios where you need to treat two separate streams as a single duplex stream for piping data through a series of transformations or operations.

What are duplexer's main functionalities?

Creating a duplex stream from a writable and readable stream

This code demonstrates how to create a duplex stream using `duplexer` by combining a writable stream, which logs data it receives, and a readable stream, which emits a single piece of data. The resulting duplex stream can be used to read data emitted by the readable stream and write data to the writable stream.

const {Writable, Readable} = require('stream');
const duplexer = require('duplexer');

const writable = new Writable({
  write(chunk, encoding, callback) {
    console.log(`Writing: ${chunk.toString()}`);
    callback();
  }
});

const readable = new Readable({
  read(size) {
    this.push('Read data');
    this.push(null); // No more data
  }
});

const duplex = duplexer(writable, readable);
duplex.on('data', (data) => console.log(`Read from duplex: ${data.toString()}`));
duplex.write('Data to write');

Other packages similar to duplexer

FAQs

Package last updated on 12 Aug 2020

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