This package, `stream-parser` (version 0.3.1), provides a generic "parser" mixin designed for Node.js `Writable` and `Transform` stream instances and subclasses. It offers a convenient API for byte-level parsing, allowing developers to implement streaming parsers for various binary file formats or network protocols. Key methods include `_bytes(n, cb)` to buffer a specified number of bytes, `_skipBytes(n, cb)` to discard bytes, and `_passthrough(n, cb)` to pass bytes through directly to the readable side of a `Transform` stream. The library was last updated over a decade ago in June 2015, indicating it is no longer actively maintained. Its primary differentiator was providing a low-level, interruptible parsing mechanism by taking control over stream's `_write` or `_transform` callbacks, which was a common pattern in older Node.js stream implementations.
npm install stream-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a custom Transform stream subclass, mixing in `stream-parser`, parsing a fixed-size header with `_bytes`, emitting an event, and then passing through the remaining stream content with `_passthrough`.
Migrate to actively maintained stream parsing libraries such as `@streamparser/json` for JSON parsing, or `parse-stream` for general binary stream parsing, which support modern Node.js stream APIs and ESM.
Be aware of these older patterns if integrating into a modern codebase. Consider alternatives that use `class MyTransform extends Transform` and standard ES6 practices for stream implementations.
If using in an ESM project, you must use dynamic `await import('stream-parser')` or configure your build system to handle CommonJS modules within an ESM context. The recommended approach for new projects is to use an ESM-first alternative.The `Parser` export is a function intended to be called with a stream's prototype or instance, e.g., `Parser(MyStream.prototype)` or `Parser(myStreamInstance)`. It is not a class or constructor.
Ensure `Parser(MyStream.prototype)` or `Parser(myStreamInstance)` has been executed before calling any `_bytes`, `_skipBytes`, or `_passthrough` methods on `this` within your stream's context.
This package is CommonJS-only. If your project is ESM, you might need to convert it to CommonJS or use `await import('stream-parser')` for dynamic imports. However, given the package's abandoned status, migrating to a modern ESM-compatible alternative is strongly advised.No dependency data recorded yet.