Registry / http-networking / bare-stream

bare-stream

JSON →
library2.13.0jsnpmunverified

bare-stream provides a lightweight and performant abstraction for handling streaming data in JavaScript environments, building upon the well-established `streamx` API. It is currently at version 2.13.0, with regular updates indicated by recent minor version bumps, suggesting an active development cadence. The "bare" prefix implies a focus on minimal overhead and core functionality, making it suitable for environments where resource efficiency is critical, such as low-resource servers or specialized applications. Unlike Node.js's built-in streams, bare-stream aims for broader compatibility and a more streamlined API, leveraging the `streamx` pattern. Its primary differentiator is its minimal dependency footprint and its explicit design for efficient data flow, providing a robust foundation for implementing custom streaming logic without the overhead of larger alternatives.

npm install bare-stream
INSTALL
IMPORT
SIG · BARE-STREAM
B
bare-stream
http-networkingjavascriptv2.13.0
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
import { Readable } from 'bare-stream'
const Readable = require('bare-stream').Readable
While CommonJS `require` is supported, named ESM imports are the recommended modern pattern for tree-shaking and future compatibility. Type declarations are automatically picked up by TypeScript when using named imports.
Writable
import { Writable } from 'bare-stream'
import Writable from 'bare-stream/writable'
All core stream classes (Readable, Writable, Transform) are exported directly from the top-level 'bare-stream' package. Avoid importing from internal paths unless explicitly documented, as they are subject to change.
Transform
import { Transform } from 'bare-stream'
const { Transform } = require('bare-stream'); // Typo or wrong destructuring
When using CommonJS, ensure correct destructuring. For TypeScript, import directly from the package to leverage type definitions effectively.

This example demonstrates creating a basic streaming pipeline using `bare-stream`. It shows a `Readable` stream generating data, a `Transform` stream processing it, and a `Writable` stream consuming and logging the final output, including basic error handling.

import { Readable, Writable, Transform } from 'bare-stream'; class MyGenerator extends Readable { constructor(limit) { super(); this.index = 0; this.limit = limit; } _read(size) { if (this.index < this.limit) { const chunk = `Data chunk ${this.index++}\n`; this.push(Buffer.from(chunk)); } else { this.push(null); // Signal end of stream } } } class MyProcessor extends Transform { _transform(chunk, encoding, callback) { // Convert to uppercase and add a prefix this.push(Buffer.from(`PROCESSED: ${chunk.toString().toUpperCase()}`)); callback(); } } class MyConsumer extends Writable { _write(chunk, encoding, callback) { console.log(chunk.toString().trim()); callback(); } } const generator = new MyGenerator(3); const processor = new MyProcessor(); const consumer = new MyConsumer(); generator.pipe(processor).pipe(consumer); // Error handling is crucial for streams generator.on('error', (err) => console.error('Generator error:', err)); processor.on('error', (err) => console.error('Processor error:', err)); consumer.on('error', (err) => console.error('Consumer error:', err)); consumer.on('finish', () => console.log('All data processed.'));
Debug
Known issues
gotchabare-stream's API closely mirrors `streamx` which has subtle differences from Node.js's built-in `stream` module. Developers accustomed to Node.js streams should review `streamx` documentation to understand variations in constructor options, `_read`/`_write` signatures, and backpressure handling.
fix
Consult the `streamx` documentation for precise API details and migration guides. Be mindful of differences in `highWaterMark` behavior and `_read` implementation.
affects: >=1.0.0
breakingWhile v2.13.0 introduced `Web TransformStream` creation, prior versions might not fully support Web Streams API compatibility. Projects targeting browser environments or Web Streams might encounter unexpected behavior on older versions.
fix
Upgrade to `bare-stream@2.13.0` or higher to leverage improved Web TransformStream compatibility. Thoroughly test stream implementations in target browser environments.
affects: <2.13.0
gotchaFailing to handle stream errors can lead to unhandled promise rejections or silent failures, potentially causing resource leaks or stalled pipelines. Each stream in a pipeline can emit an 'error' event independently.
fix
Always attach an 'error' event listener to every stream in your pipeline. For complex pipelines, consider using `pipeline` from 'node:stream/promises' (or a compatible utility) for automatic error propagation and resource cleanup.
affects: >=1.0.0
gotchaIncorrect backpressure management in stream implementations can lead to memory exhaustion when a producer stream overwhelms a slower consumer. This is especially critical in high-throughput scenarios.
fix
Ensure your custom `_read` and `_write` implementations correctly respect the `callback` argument. For `Readable` streams, `_read` should only push data when `push` returns `true` or when explicitly called after a `_read` trigger. For `Writable` streams, `callback` should be invoked only after the chunk is fully processed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: stream.pipe is not a function
Attempting to use `.pipe()` on an object that is not a bare-stream (or streamx-compatible) instance, or on an instance that has been incorrectly initialized.
fix
Ensure that the object you are calling `.pipe()` on is an instance of `bare-stream.Readable` or `bare-stream.Transform`. Verify imports and constructor calls.
ERR_STREAM_WRITE_AFTER_END: write after end
Attempting to write data to a Writable or Transform stream after its `end()` method has been called or a `null` chunk has been pushed, signifying the end of the writable side.
fix
Check your logic for when data is being written to the stream. Ensure that no `write()` calls occur after `stream.end()` or after `this.push(null)` in a `Transform` stream, unless specifically designed for that behavior.
ReferenceError: Readable is not defined
The `Readable` class (or Writable, Transform) was not correctly imported or required into the scope before being used.
fix
Add `import { Readable } from 'bare-stream'` (for ESM) or `const { Readable } = require('bare-stream')` (for CJS) at the top of your file to make the class available.
Upgrade
Version history
2.13.0latest on npm
Audit
Dependencies
bare-abort-controllerrequiredProvides an AbortController implementation for stream cancellation and signal handling across different JavaScript environments.
bare-bufferrequiredOffers a Buffer implementation, essential for efficient binary data handling within streams, especially for consistency across Node.js and browser contexts.
bare-eventsrequiredSupplies an EventEmitter-like interface for managing event emission and listening within stream instances, crucial for internal stream mechanics and user interaction.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
bare-stream — npm install bare-stream · libregistry