Registry / http-networking / lazystream

lazystream

JSON →
library0.1.6jsnpmunverified

lazystream is a Node.js utility library designed to address the "too many open files" (EMFILE) error by creating readable and writable streams on demand. Instead of eagerly opening file handles or other resources upon instantiation, it wraps stream creation functions, deferring the actual stream initialization until the stream is actively accessed (e.g., read from, written to, or piped). The current stable version is 1.0.1, released in 2016. The package provides `lazystream.Readable` and `lazystream.Writable` classes, which internally extend Node's `stream.PassThrough` by relying on `readable-stream@2.x` for a stable Streams3 API implementation. This approach allows developers to pass around stream proxies without immediate resource allocation, offering a simple, callback-based mechanism to encapsulate stream creation logic. However, the package is no longer actively maintained.

npm install lazystream
INSTALL
IMPORT
SIG · LAZYSTREAM
L
lazystream
http-networkingjavascriptv0.1.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Readable
const { Readable } = require('lazystream');
import { Readable } from 'lazystream';
The package is CommonJS-only. Destructuring assignment is common for class imports.
Writable
const { Writable } = require('lazystream');
import { Writable } from 'lazystream';
The package is CommonJS-only. Destructuring assignment is common for class imports.
lazystream (namespace)
const lazystream = require('lazystream');
import lazystream from 'lazystream';
The primary way to import the package as a whole, providing access to `lazystream.Readable` and `lazystream.Writable`.

Demonstrates how to create lazy readable and writable streams using `lazystream`, deferring the actual file opening until data is piped, and then cleans up the temporary files.

const lazystream = require('lazystream'); const fs = require('fs'); const path = require('path'); // Create a dummy file for reading const inputFile = path.join(__dirname, 'input.txt'); fs.writeFileSync(inputFile, 'Hello, lazy stream!'); // Define the output file const outputFile = path.join(__dirname, 'output.txt'); console.log('Creating lazy streams...'); // Create a lazy readable stream const lazyReadable = new lazystream.Readable(function () { console.log(' -> Actually opening read stream now.'); return fs.createReadStream(inputFile); }); // Create a lazy writable stream const lazyWritable = new lazystream.Writable(function () { console.log(' -> Actually opening write stream now.'); return fs.createWriteStream(outputFile); }); console.log('Lazy streams instantiated, but file handles are not yet open.'); // Pipe the lazy readable to the lazy writable lazyReadable.pipe(lazyWritable) .on('finish', () => { console.log('Piping finished. Content written to output.txt'); const content = fs.readFileSync(outputFile, 'utf8'); console.log('Output file content:', content); // Clean up fs.unlinkSync(inputFile); fs.unlinkSync(outputFile); }) .on('error', (err) => { console.error('Stream error:', err); // Clean up in case of error if (fs.existsSync(inputFile)) fs.unlinkSync(inputFile); if (fs.existsSync(outputFile)) fs.unlinkSync(outputFile); }); console.log('Piping operation initiated. Streams will open on first data access.');
Debug
Known issues
breakingVersion 1.0.0 unconditionally switched its internal stream implementation to `readable-stream@2.x`. While this improved stability across Node.js versions, it represents a breaking change in internal dependency and potential behavior for users relying on specific `readable-stream` versions.
fix
Ensure compatibility with `readable-stream@2.x` and verify stream behavior if upgrading from pre-1.0.0 versions.
affects: >=1.0.0
deprecatedThe `lazystream` package is no longer actively maintained. Its last significant update was in 2016. Use at your own risk, and consider alternative solutions for modern Node.js applications.
fix
Evaluate active stream management libraries or implement custom lazy stream logic for long-term projects.
affects: >=1.0.1
gotchaDespite using `readable-stream` for Streams3 API compatibility, the package's age means it may not fully support or interact correctly with newer Node.js stream APIs (e.g., Streams4/5) introduced in later Node.js versions, potentially leading to unexpected behavior or incompatibilities.
fix
Thoroughly test `lazystream` in your target Node.js environment, especially with recent Node.js releases. Be prepared to refactor if compatibility issues arise.
affects: >=1.0.1
Errors
Common errors & fixes
Error: EMFILE, too many open files
Attempting to open too many file descriptors simultaneously without proper resource management, exceeding system limits.
fix
Implement `lazystream.Readable` or `lazystream.Writable` to defer the creation of stream resources until they are actually needed, preventing premature resource exhaustion.
TypeError: stream.pipe is not a function
Attempting to call `.pipe()` on an object that is not a valid stream, or using an incompatible stream version/implementation.
fix
Ensure the object is a valid `lazystream.Readable` or `lazystream.Writable` instance (which extends `stream.PassThrough`), or a compatible Node.js Stream. Check Node.js and `readable-stream` versions for compatibility.
Cannot find module 'lazystream'
The `lazystream` package was not installed or is not accessible in the current project's `node_modules`.
fix
Run `npm install lazystream --save` in your project directory to install the package.
Upgrade
Version history
0.1.6latest on npm
Audit
Dependencies
readable-streamrequiredProvides a stable Streams3 API implementation, decoupled from Node.js core versions, enabling consistent lazy stream functionality.
Agent activity
2 hits · last 30 days
node
2
Resources
lazystream — npm install lazystream · libregistry