node-readable-to-web-readable-stream is a utility that converts a Node.js Readable
stream into a WHATWG-compatible ReadableStream
. This is particularly useful for integrating Node.js streams with web-native streaming APIs.
Install the package using npm:
npm install node-readable-to-web-readable-stream
Or with yarn:
yarn add node-readable-to-web-readable-stream
Here's how you can use this utility to convert a Node.js Readable
stream into a web ReadableStream
:
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
This is an ECMAScript Module (ESM).
-
Parameters:
nodeReadable
(Node.jsReadable
): The Node.js Readable stream to convert.
-
Returns:
- A WHATWG-compatible
ReadableStream
.
- A WHATWG-compatible
This project is licensed under the MIT License. See the LICENSE file for details.