Socket
Socket
Sign inDemoInstall

cloneable-readable

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloneable-readable

Clone a Readable stream, safely


Version published
Maintainers
1
Created

What is cloneable-readable?

The cloneable-readable npm package allows you to create cloneable versions of Node.js readable streams. This means you can create multiple independent readers from a single readable stream, which can be useful in scenarios where you need to process the same stream data in different ways simultaneously.

What are cloneable-readable's main functionalities?

Cloning a Readable Stream

This feature allows you to clone a readable stream. The code sample demonstrates how to create a cloneable version of a readable stream and then read data from both the original and cloned streams.

const cloneable = require('cloneable-readable');
const { Readable } = require('stream');

const originalStream = new Readable({
  read() {
    this.push('data');
    this.push(null);
  }
});

const clonedStream = cloneable(originalStream);

clonedStream.on('data', (chunk) => {
  console.log(`Cloned stream data: ${chunk}`);
});

originalStream.on('data', (chunk) => {
  console.log(`Original stream data: ${chunk}`);
});

Multiple Clones

This feature allows you to create multiple clones of a readable stream. The code sample demonstrates how to create two clones from the original stream and read data from both clones.

const cloneable = require('cloneable-readable');
const { Readable } = require('stream');

const originalStream = new Readable({
  read() {
    this.push('data');
    this.push(null);
  }
});

const clonedStream1 = cloneable(originalStream);
const clonedStream2 = clonedStream1.clone();

clonedStream1.on('data', (chunk) => {
  console.log(`Cloned stream 1 data: ${chunk}`);
});

clonedStream2.on('data', (chunk) => {
  console.log(`Cloned stream 2 data: ${chunk}`);
});

Other packages similar to cloneable-readable

Keywords

FAQs

Package last updated on 25 Oct 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