Convert Node Readable to Web API ReadableStream
npm install node-readable-to-web-readable-stream


bash
npm install node-readable-to-web-readable-stream
`
Or with yarn:
`bash
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.
`javascript
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.
`javascript
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
$3
- Parameters:
- nodeReadable (Node.js stream.Readable): The Node.js Readable stream to convert.
- options Optional: {highWaterMark?: number}`, high-water mark in bytes, default 16 kB.