{"id":16039,"library":"from2","title":"from2: Readable Stream Wrapper","description":"from2 is a convenience wrapper for Node.js `ReadableStream` (specifically, the `readable-stream` base class), designed to simplify the creation of readable streams while correctly handling backpressure. The current stable version is 2.3.0, published in 2016, indicating the project is likely abandoned or in long-term maintenance with no active development or planned release cadence. It differentiates itself by offering an API inspired by `from` and `through2`, providing `from2.obj` for object mode streams and `from2.ctor` for creating reusable stream constructors, which can improve performance for multiple similar streams. It aims to make stream creation more approachable than direct `ReadableStream` implementation.","status":"abandoned","version":"2.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/hughsk/from2","tags":["javascript","from","stream","readable","pull","convenience","wrapper"],"install":[{"cmd":"npm install from2","lang":"bash","label":"npm"},{"cmd":"yarn add from2","lang":"bash","label":"yarn"},{"cmd":"pnpm add from2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying ReadableStream base class that from2 wraps. This is a core runtime dependency.","package":"readable-stream"}],"imports":[{"note":"from2 is a CommonJS module. Direct ES module `import` syntax will not work without a transpiler or Node.js's experimental CommonJS-to-ESM interop features, which may lead to unexpected behavior or require dynamic `import()`.","wrong":"import from from 'from2'","symbol":"from","correct":"const from = require('from2')"},{"note":"`obj` is a property of the default export, not a named export. Attempting to destructure it as a named import will fail.","wrong":"import { obj } from 'from2'","symbol":"from.obj","correct":"const from = require('from2'); const objStream = from.obj(...)"},{"note":"Similar to `obj`, `ctor` is a property of the CommonJS default export, not a named export.","wrong":"import { ctor } from 'from2'","symbol":"from.ctor","correct":"const from = require('from2'); const StreamConstructor = from.ctor(...)"}],"quickstart":{"code":"const from = require('from2');\n\nfunction fromString(string) {\n  return from(function(size, next) {\n    // if there's no more content\n    // left in the string, close the stream.\n    if (string.length <= 0) return next(null, null);\n\n    // Pull in a new chunk of text,\n    // removing it from the string.\n    var chunk = string.slice(0, size);\n    string = string.slice(size);\n\n    // Emit \"chunk\" from the stream.\n    next(null, chunk);\n  });\n}\n\n// pipe \"hello world\" out\n// to stdout.\nfromString('hello world').pipe(process.stdout);","lang":"javascript","description":"This example demonstrates how to create a basic readable stream using `from2` that emits chunks of a given string, handling backpressure appropriately, and then pipes it to standard output."},"warnings":[{"fix":"Be aware that the API, while stable in its current form, was once considered experimental. Thorough testing is recommended if relying on specific undocumented behaviors.","message":"The package displays an 'experimental' stability badge in its README. While functional, this historically implied that its API or behavior might not be fully stable or guaranteed for long-term production use without potential changes. Given its age, no further stabilization is expected.","severity":"gotcha","affected_versions":"<=2.3.0"},{"fix":"Evaluate modern stream implementations like Node.js's native `stream.Readable` or newer libraries that are actively maintained. Consider forking the project or implementing custom stream logic if specific `from2` behavior is critical and security/maintenance concerns are addressed internally.","message":"This package is no longer actively maintained. The last release was over 7 years ago (as of 2026). This means it will not receive updates for new Node.js features, critical bug fixes, or security patches, potentially exposing applications to vulnerabilities or compatibility issues with newer environments.","severity":"breaking","affected_versions":">=2.3.0"},{"fix":"Always use `const from = require('from2')` for Node.js applications. If you must use `from2` in an ESM context, consider a bundler like Webpack or Rollup, or use `import from2 from 'from2'` (for default export) followed by `from2.obj` or `from2.ctor`. However, the direct `import { obj } from 'from2'` will not work.","message":"`from2` is built on CommonJS module syntax (`require`). Attempting to use ES module `import` syntax directly in an ESM context will likely fail or require complex interoperability solutions (e.g., dynamic `import()`), as named exports from CJS modules are not directly supported by `import { Name } from 'cjs-module'`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use CommonJS `require` for `from2` and access properties directly: `const from = require('from2'); const myStream = from.obj(...)`.","cause":"Attempting to import `obj` or `ctor` as a named ES module import, e.g., `import { obj } from 'from2'` in an ESM file.","error":"TypeError: from2.obj is not a function"},{"fix":"Ensure your project or build system correctly handles `from2` as a CommonJS module. If you are in an ESM context and cannot avoid `from2`, use dynamic `import('from2')` and then access the default export's properties, e.g., `(await import('from2')).default.obj(...)`. Note that `from2` itself is CJS, so `require` should generally work.","cause":"Trying to `require('from2')` from an ES module file (`.mjs` or `type: module` in `package.json`) if a hypothetical future version of from2 were ESM-only, or if a build process incorrectly targets ESM for `from2`. This specific error is unlikely for `from2` itself given its age and CJS nature, but represents a common interop issue.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... from2.js not supported."}],"ecosystem":"npm"}