Hemifield/Codex-storage / home /.codex /computer-use /linux /runtime /lib /node_modules /node-readable-to-web-readable-stream
17.6 GB
46,368 files
Updated about 1 month ago
Name
Size
lib
LICENSE.txt1.09 kB
xet
README.md3.71 kB
xet
package.json1.3 kB
xet
README.md

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.

Total size
17.6 GB
Files
46,368
Last updated
Sep 9
Pre-warmed CDN
US EU US EU

Contributors