Socket
Socket
Sign inDemoInstall

readable-stream

Package Overview
Dependencies
4
Maintainers
4
Versions
103
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

readable-stream

Streams2, a user-land copy of the stream library from Node.js v0.10.x


Version published
Maintainers
4
Weekly downloads
138,307,229
decreased by-10.34%

Weekly downloads

Package description

What is readable-stream?

The readable-stream package is a userland stream module, compatible with the built-in stream module provided by Node.js. It offers the same interface and functionality as the native module, but with additional updates and bug fixes. It is particularly useful for ensuring consistent stream behavior across different Node.js versions.

What are readable-stream's main functionalities?

Creating a readable stream

This feature allows you to create a readable stream that you can pipe to other streams or consume manually. The 'read' method is called when the stream wants to pull more data.

const { Readable } = require('readable-stream');
const myReadableStream = new Readable({
  read(size) {
    this.push('some data');
    this.push(null); // No more data
  }
});
myReadableStream.on('data', (chunk) => {
  console.log(chunk.toString());
});

Creating a writable stream

This feature allows you to create a writable stream where you can write data. The 'write' method is called when the stream receives data to write.

const { Writable } = require('readable-stream');
const myWritableStream = new Writable({
  write(chunk, encoding, callback) {
    process.stdout.write(chunk);
    callback();
  }
});
process.stdin.pipe(myWritableStream);

Creating a transform stream

This feature allows you to create a transform stream that can modify data as it is read from a readable stream before it is written to a writable stream.

const { Transform } = require('readable-stream');
const myTransformStream = new Transform({
  transform(chunk, encoding, callback) {
    this.push(chunk.toString().toUpperCase());
    callback();
  }
});
process.stdin.pipe(myTransformStream).pipe(process.stdout);

Creating a duplex stream

This feature allows you to create a duplex stream that is both readable and writable. It can be used to read data from one source and write to another.

const { Duplex } = require('readable-stream');
const myDuplexStream = new Duplex({
  read(size) {
    this.push('data from read method');
    this.push(null);
  },
  write(chunk, encoding, callback) {
    console.log(chunk.toString());
    callback();
  }
});
myDuplexStream.on('data', (chunk) => {
  console.log(chunk.toString());
});
myDuplexStream.write('data for write method');

Other packages similar to readable-stream

Readme

Source

readable-stream

Node-core streams for userland

NPM NPM

This package is a mirror of the Streams2 and Streams3 implementations in Node-core.

If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use readable-stream only and avoid the "stream" module in Node-core.

readable-stream comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12.

readable-stream uses proper patch-level versioning so if you pin to "~1.0.0" you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the 1.0.x releases for now and when you’re ready to start using Streams3, pin to "~1.1.0"

Keywords

FAQs

Last updated on 13 Apr 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc