{"id":10562,"library":"bare-stream","title":"bare-stream","description":"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.","status":"active","version":"2.13.0","language":"javascript","source_language":"en","source_url":"https://github.com/holepunchto/bare-stream","tags":["javascript","typescript"],"install":[{"cmd":"npm install bare-stream","lang":"bash","label":"npm"},{"cmd":"yarn add bare-stream","lang":"bash","label":"yarn"},{"cmd":"pnpm add bare-stream","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides an AbortController implementation for stream cancellation and signal handling across different JavaScript environments.","package":"bare-abort-controller","optional":false},{"reason":"Offers a Buffer implementation, essential for efficient binary data handling within streams, especially for consistency across Node.js and browser contexts.","package":"bare-buffer","optional":false},{"reason":"Supplies an EventEmitter-like interface for managing event emission and listening within stream instances, crucial for internal stream mechanics and user interaction.","package":"bare-events","optional":false}],"imports":[{"note":"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.","wrong":"const Readable = require('bare-stream').Readable","symbol":"Readable","correct":"import { Readable } from 'bare-stream'"},{"note":"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.","wrong":"import Writable from 'bare-stream/writable'","symbol":"Writable","correct":"import { Writable } from 'bare-stream'"},{"note":"When using CommonJS, ensure correct destructuring. For TypeScript, import directly from the package to leverage type definitions effectively.","wrong":"const { Transform } = require('bare-stream'); // Typo or wrong destructuring","symbol":"Transform","correct":"import { Transform } from 'bare-stream'"}],"quickstart":{"code":"import { Readable, Writable, Transform } from 'bare-stream';\n\nclass MyGenerator extends Readable {\n  constructor(limit) {\n    super();\n    this.index = 0;\n    this.limit = limit;\n  }\n\n  _read(size) {\n    if (this.index < this.limit) {\n      const chunk = `Data chunk ${this.index++}\\n`;\n      this.push(Buffer.from(chunk));\n    } else {\n      this.push(null); // Signal end of stream\n    }\n  }\n}\n\nclass MyProcessor extends Transform {\n  _transform(chunk, encoding, callback) {\n    // Convert to uppercase and add a prefix\n    this.push(Buffer.from(`PROCESSED: ${chunk.toString().toUpperCase()}`));\n    callback();\n  }\n}\n\nclass MyConsumer extends Writable {\n  _write(chunk, encoding, callback) {\n    console.log(chunk.toString().trim());\n    callback();\n  }\n}\n\nconst generator = new MyGenerator(3);\nconst processor = new MyProcessor();\nconst consumer = new MyConsumer();\n\ngenerator.pipe(processor).pipe(consumer);\n\n// Error handling is crucial for streams\ngenerator.on('error', (err) => console.error('Generator error:', err));\nprocessor.on('error', (err) => console.error('Processor error:', err));\nconsumer.on('error', (err) => console.error('Consumer error:', err));\nconsumer.on('finish', () => console.log('All data processed.'));","lang":"typescript","description":"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."},"warnings":[{"fix":"Consult the `streamx` documentation for precise API details and migration guides. Be mindful of differences in `highWaterMark` behavior and `_read` implementation.","message":"bare-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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `bare-stream@2.13.0` or higher to leverage improved Web TransformStream compatibility. Thoroughly test stream implementations in target browser environments.","message":"While 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.","severity":"breaking","affected_versions":"<2.13.0"},{"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.","message":"Failing 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Incorrect 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"TypeError: stream.pipe is not a function"},{"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.","cause":"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.","error":"ERR_STREAM_WRITE_AFTER_END: write after end"},{"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.","cause":"The `Readable` class (or Writable, Transform) was not correctly imported or required into the scope before being used.","error":"ReferenceError: Readable is not defined"}],"ecosystem":"npm"}