Registry /
serialization / node-readable-to-web-readable-stream
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
makeByteReadableStreamFromNodeReadable
✓ import { makeByteReadableStreamFromNodeReadable } from 'node-readable-to-web-readable-stream';
✗ const makeByteReadableStreamFromNodeReadable = require('node-readable-to-web-readable-stream').makeByteReadableStreamFromNodeReadable;
This package is primarily an ESM. CommonJS `require()` is only officially supported for Node.js >= 22.
makeDefaultReadableStreamFromNodeReadable
✓ import { makeDefaultReadableStreamFromNodeReadable } from 'node-readable-to-web-readable-stream';
✗ const { makeDefaultReadableStreamFromNodeReadable } = require('node-readable-to-web-readable-stream');
Added in v0.4.0. For converting to a default-mode Web ReadableStream, often used with ReadableStreamDefaultReader.
toWebReadableStream
✓ import { toWebReadableStream } from 'node-readable-to-web-readable-stream';
✗ const toWebReadableStream = require('node-readable-to-web-readable-stream').toWebReadableStream;
A general conversion function documented in the API. The `makeByteReadableStreamFromNodeReadable` and `makeDefaultReadableStreamFromNodeReadable` functions are generally preferred for explicit stream type conversion.
NodeJS.ReadableStream
✓ import type { Readable } from 'node:stream';
When providing a Node.js Readable stream, import its type from `node:stream` for type safety.
Demonstrates converting a Node.js `fs.createReadStream` into a Web API `ReadableStream` (byte mode) and consuming it with a BYOB reader.
import { createReadStream } from 'node:fs';
import { makeByteReadableStreamFromNodeReadable } from 'node-readable-to-web-readable-stream';
// Imagine 'large-file.bin' is a large binary file
// Create a Node.js Readable stream
const nodeReadable = createReadStream('large-file.bin');
// Convert to a web ReadableStream, specifically a byte stream for BYOB support
const webReadable = makeByteReadableStreamFromNodeReadable(nodeReadable);
// Example: Consume the webReadable using a BYOB reader
async function readStream(stream: ReadableStream<Uint8Array>) {
const reader = stream.getReader({ mode: 'byob' });
try {
while (true) {
const { value, done } = await reader.read(new Uint8Array(1024)); // Read into a pre-allocated buffer
if (done) {
console.log('Stream finished.');
break;
}
if (value) {
console.log(`Read ${value.byteLength} bytes.`);
// Process the chunk here
}
}
} catch (error) {
console.error('Error reading stream:', error);
} finally {
reader.releaseLock();
}
}
// In a real application, you'd ensure 'large-file.bin' exists or create it.
// For demonstration, we'll create a dummy file if it doesn't exist.
import { promises as fsPromises } from 'node:fs';
async function setupAndRun() {
try {
await fsPromises.access('large-file.bin');
} catch (error) {
await fsPromises.writeFile('large-file.bin', Buffer.alloc(1024 * 1024, 'A')); // 1MB dummy file
console.log('Created dummy large-file.bin');
}
readStream(webReadable);
}
setupAndRun();
Errors
Common errors & fixes
TypeError: makeByteReadableStreamFromNodeReadable is not a function
Attempting to `require()` the module in a Node.js version older than 22, or in a CommonJS context where ESM imports are not correctly transpiled or handled.
fixEnsure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) and use `import { makeByteReadableStreamFromNodeReadable } from 'node-readable-to-web-readable-stream';`. If using Node.js < 22, you cannot reliably use `require()` for this package. Web ReadableStream stops emitting data unexpectedly or seems to freeze.
This is often a symptom of the stream hanging bug fixed in earlier versions, where the converted stream would not properly signal completion or handle cancellation.
fixUpgrade the package to version `0.4.1` or newer. This version specifically addressed issues causing converted byte ReadableStreams to hang.
Audit
Dependencies
No dependency data recorded yet.