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

web-streams-polyfill

Package Overview
Dependencies
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web-streams-polyfill

Web Streams, based on the WHATWG spec reference implementation

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10M
decreased by-19.3%
Maintainers
3
Weekly downloads
 
Created

What is web-streams-polyfill?

The web-streams-polyfill package is a polyfill for the Streams API, which provides a standard interface for representing and handling a sequence of data in JavaScript. This polyfill allows developers to use the Streams API in environments where it is not natively supported.

What are web-streams-polyfill's main functionalities?

ReadableStream

This feature allows you to create a stream of data that can be read in chunks. The code sample demonstrates how to create a simple ReadableStream that enqueues two chunks of data and then closes the stream.

const readableStream = new ReadableStream({
  start(controller) {
    controller.enqueue('Hello, ');
    controller.enqueue('World!');
    controller.close();
  }
});

readableStream.getReader().read().then(({ value, done }) => {
  if (!done) console.log(value);
});

WritableStream

This feature allows you to create a stream where data can be written. The code sample shows how to create a WritableStream and write a chunk of data to it, then close the stream.

const writableStream = new WritableStream({
  write(chunk) {
    console.log(chunk);
  },
  close() {
    console.log('Stream closed');
  }
});

const writer = writableStream.getWriter();
writer.write('Hello, World!').then(() => writer.close());

TransformStream

This feature allows you to create a stream that transforms data as it passes through. The code sample demonstrates how to create a TransformStream that converts chunks of text to uppercase and then pipes data from a ReadableStream through it to a WritableStream.

const uppercaseTransform = new TransformStream({
  transform(chunk, controller) {
    controller.enqueue(chunk.toUpperCase());
  }
});

const readable = new ReadableStream({
  start(controller) {
    controller.enqueue('hello');
    controller.enqueue('world');
    controller.close();
  }
});

const writable = new WritableStream({
  write(chunk) {
    console.log(chunk);
  }
});

readable.pipeThrough(uppercaseTransform).pipeTo(writable);

Other packages similar to web-streams-polyfill

Keywords

FAQs

Package last updated on 28 Feb 2024

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