Registry / http-networking / stream-parser

stream-parser

JSON →
library0.3.1jsnpmunverified

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-parser
INSTALL
IMPORT
SIG · STREAM-PARSER
S
stream-parser
http-networkingjavascriptv0.3.1
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.

Parser
const Parser = require('stream-parser');
import Parser from 'stream-parser'; // Not supported, package is CommonJS only import { Parser } from 'stream-parser'; // Not supported, no named exports
This package is a CommonJS module and does not provide ESM exports. It exports a function intended to be used as a mixin, not a class constructor.

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`.

const Parser = require('stream-parser'); const inherits = require('util').inherits; const { Transform } = require('stream'); // Create a Transform stream subclass that utilizes stream-parser function MyParser () { Transform.call(this); // Buffer the first 8 bytes written, then call onheader this._bytes(8, this.onheader); } inherits(MyParser, Transform); // Mixin stream-parser into MyParser's `prototype` Parser(MyParser.prototype); // Invoked when the first 8 bytes have been received MyParser.prototype.onheader = function (buffer) { // Parse the 'buffer' into a useful 'header' object const header = {}; // Assuming a theoretical 4-byte type and 4-byte UTF-8 name header.type = buffer.readUInt32LE(0); header.name = buffer.toString('utf8', 4, 8); this.emit('header', header); // After parsing the header, pass through the rest of the data indefinitely this._passthrough(Infinity); }; // Now we can *use* it! const parser = new MyParser(); parser.on('header', (header) => { console.log('Got header:', header); }); // Example usage: pipe some data to the parser const data = Buffer.from('01000000TESTHEADER' + 'This is the rest of the stream content.', 'latin1'); const input = new Transform(); input._read = () => {}; // Implement a dummy _read method for the input stream input.push(data); input.push(null); // End the input stream input.pipe(parser).pipe(process.stdout); // Expected output: 'Got header: { type: 1, name: 'TEST' }' (to console.log) and 'HEADERThis is the rest of the stream content.' (to stdout)
Debug
Known issues
breakingThis package is considered abandoned, with its last release over a decade ago (version 0.3.1, last published June 2015). It is not recommended for new projects due to a lack of maintenance, potential compatibility issues with modern Node.js versions, and absence of critical updates or security patches.
fix
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.
affects: >=0.3.1
gotchaThe package uses older Node.js stream API patterns, including directly manipulating `_write` and `_transform` callbacks and using `util.inherits` for class extension. This approach is less idiomatic in modern Node.js, which favors ES6 classes and `stream.pipeline` or `stream.compose` for stream manipulation.
fix
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.
affects: >=0.1.0
gotchaThis package is a CommonJS module and does not offer native ECMAScript Module (ESM) support. Attempting to `import` it directly in an ESM context will result in a runtime error.
fix
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.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Parser is not a constructor
Attempting to instantiate `Parser` using `new Parser()` instead of applying it as a mixin to a prototype or instance.
fix
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.
TypeError: this._bytes is not a function
The `stream-parser` mixin has not been correctly applied to the stream instance or prototype, or `_bytes` is called outside the context of a stream with the mixin.
fix
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.
ERR_REQUIRE_ESM
Attempting to `require('stream-parser')` from an ECMAScript Module (ESM) context in Node.js, which is not directly supported by this CommonJS-only package.
fix
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.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
stream-parser — npm install stream-parser · libregistry