node-readable-to-web-readable-stream
Convert Node Readable to Web API ReadableStream
Last updated a year ago by borewit .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install node-readable-to-web-readable-stream 
SYNC missed versions from official npm registry.

CI NPM version NPM downloads

node-readable-to-web-readable-stream

node-readable-to-web-readable-stream is a utility that converts a Node.js stream.Readable stream into a Web API ReadableStream. This is particularly useful for integrating Node.js streams with web-native streaming APIs.

To convert in the opposite direction, see may use readable-web-to-node-stream instead.

Installation

Install the package using npm:

npm install node-readable-to-web-readable-stream

Or with yarn:

yarn add node-readable-to-web-readable-stream

Usage

You can either convert to a WHATWG / Web API ReadableStream byte mode, or default mode.

Here's how you can use this utility to convert a Node.js stream.Readable stream into a byte WHATWG / Web API ReadableStream: If you want to use a ReadableStreamBYOBReader you should use this method.

import {makeByteReadableStreamFromNodeReadable} from 'node-readable-to-web-readable-stream';
import {createReadStream} from 'fs';

// Create a Node.js Readable stream
const nodeReadable = fs.createReadStream('example.txt');

// Convert to a web ReadableStream
const webReadable = makeByteReadableStreamFromNodeReadable(nodeReadable);

// Now you can use webReadable as a WHATWG ReadableStream in byte mode

If you want to use a ReadableStreamDefaultReader you should use this method.

import {makeDefaultReadableStreamFromNodeReadable} from 'node-readable-to-web-readable-stream';
import {createReadStream} from 'fs';

// Create a Node.js Readable stream
const nodeReadable = fs.createReadStream('example.txt');

// Convert to a web ReadableStream
const webReadable = makeDefaultReadableStreamFromNodeReadable(nodeReadable);

// Now you can use webReadable as a WHATWG default ReadableStream

Compatibility

This is an ECMAScript Module (ESM). Cross-platform compliant:

  • Node.js ≥ 18
  • Bum ≥ 1.2
  • Modern web browsers

You can load the project with require in Node.js ≥ 22

Features

  • Supports stream backpressure
  • BYOB (Bring Your Own Buffer) compliant

API

toWebReadableStream(nodeReadable, options)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Current Tags

  • 0.4.2                                ...           latest (a year ago)

10 Versions

  • 0.4.2                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org | Home |