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

stream-browserify

Package Overview
Dependencies
Maintainers
40
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-browserify

the stream module from node core for browsers

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14M
increased by10.57%
Maintainers
40
Weekly downloads
 
Created

What is stream-browserify?

The stream-browserify npm package is a browser-compatible version of Node.js's core stream module. It allows developers to use stream-based operations in browser environments, similar to how they would in Node.js. This includes the ability to create readable, writable, duplex, and transform streams, which can be used for handling data in a more efficient and modular way.

What are stream-browserify's main functionalities?

Creating a Readable Stream

This code sample demonstrates how to create a readable stream that emits data from an array. Each chunk of data is pushed to the stream and logged to the console when the 'data' event is emitted.

const Stream = require('stream-browserify');
let data = ['stream', 'browserify'];
let readable = Stream.Readable({
  read(size) {
    if (data.length === 0) this.push(null);
    else this.push(data.shift());
  }
});
readable.on('data', (chunk) => {
  console.log(chunk.toString());
});

Creating a Writable Stream

This code sample shows how to create a writable stream that logs any data written to it to the console.

const Stream = require('stream-browserify');
let writable = new Stream.Writable({
  write(chunk, encoding, callback) {
    console.log(chunk.toString());
    callback();
  }
});
writable.write('Hello, world!');

Piping Streams

This example demonstrates how to pipe data from a readable stream directly into a writable stream. The data from the readable stream is logged to the console as it's written to the writable stream.

const Stream = require('stream-browserify');
let readable = Stream.Readable.from(['stream', 'browserify']);
let writable = new Stream.Writable({
  write(chunk, encoding, callback) {
    console.log(chunk.toString());
    callback();
  }
});
readable.pipe(writable);

Transform Stream

This code sample illustrates how to create a transform stream that converts any input data to uppercase. The transform stream is piped from stdin and then piped to stdout, effectively creating a stream that uppercases input from the command line.

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

Other packages similar to stream-browserify

Keywords

FAQs

Package last updated on 16 Apr 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