{"id":14061,"library":"stream-parser","title":"Stream Parser Mixin for Node.js Streams","description":"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.","status":"abandoned","version":"0.3.1","language":"javascript","source_language":"en","source_url":"git://github.com/TooTallNate/node-stream-parser","tags":["javascript"],"install":[{"cmd":"npm install stream-parser","lang":"bash","label":"npm"},{"cmd":"yarn add stream-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add stream-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import Parser from 'stream-parser'; // Not supported, package is CommonJS only\nimport { Parser } from 'stream-parser'; // Not supported, no named exports","symbol":"Parser","correct":"const Parser = require('stream-parser');"}],"quickstart":{"code":"const Parser = require('stream-parser');\nconst inherits = require('util').inherits;\nconst { Transform } = require('stream');\n\n// Create a Transform stream subclass that utilizes stream-parser\nfunction MyParser () {\n  Transform.call(this);\n\n  // Buffer the first 8 bytes written, then call onheader\n  this._bytes(8, this.onheader);\n}\ninherits(MyParser, Transform);\n\n// Mixin stream-parser into MyParser's `prototype`\nParser(MyParser.prototype);\n\n// Invoked when the first 8 bytes have been received\nMyParser.prototype.onheader = function (buffer) {\n  // Parse the 'buffer' into a useful 'header' object\n  const header = {};\n  // Assuming a theoretical 4-byte type and 4-byte UTF-8 name\n  header.type = buffer.readUInt32LE(0);\n  header.name = buffer.toString('utf8', 4, 8);\n  this.emit('header', header);\n\n  // After parsing the header, pass through the rest of the data indefinitely\n  this._passthrough(Infinity);\n};\n\n// Now we can *use* it!\nconst parser = new MyParser();\nparser.on('header', (header) => {\n  console.log('Got header:', header);\n});\n\n// Example usage: pipe some data to the parser\nconst data = Buffer.from('01000000TESTHEADER' + 'This is the rest of the stream content.', 'latin1');\nconst input = new Transform();\ninput._read = () => {}; // Implement a dummy _read method for the input stream\ninput.push(data);\ninput.push(null); // End the input stream\n\ninput.pipe(parser).pipe(process.stdout);\n// Expected output: 'Got header: { type: 1, name: 'TEST' }' (to console.log) and 'HEADERThis is the rest of the stream content.' (to stdout)","lang":"javascript","description":"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`."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=0.3.1"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.3.1':13 '2015':100 'activ':106 'ago':97 'allow':39 'api':33 'binari':47 'buffer':60 'byte':36,56,65,71,78 'byte-level':35 'callback':129 'cb':58,68,75 'common':133 'control':122 'conveni':32 'decad':96 'design':19 'develop':40 'differenti':110 'direct':80 'discard':70 'file':48 'format':49 'generic':16 'implement':42,139 'includ':55 'indic':101 'instanc':26 'interrupt':117 'javascript':140 'june':99 'key':53 'last':92 'level':37,116 'librari':90 'longer':105 'low':115 'low-level':114 'maintain':107 'mechan':119 'method':54 'mixin':3,18 'n':57,67,74 'network':51 'node.js':5,21,137 'number':63 'offer':30 'older':136 'packag':8 'pars':38,118 'parser':2,11,17,44 'pass':77 'passthrough':73 'pattern':134 'primari':109 'protocol':52 'provid':14,112 'readabl':83 'side':84 'skipbyt':66 'specifi':62 'stream':1,6,10,25,43,88,124,138 'stream-pars':9 'subclass':28 'take':121 'transform':24,87,128 'updat':93 'various':46 'version':12 'writabl':22 'write':126","created_at":"2026-04-20T01:57:43.907054+00:00","updated_at":"2026-04-20T01:57:43.907054+00:00","problems":[{"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.","cause":"Attempting to instantiate `Parser` using `new Parser()` instead of applying it as a mixin to a prototype or instance.","error":"TypeError: Parser is not a constructor"},{"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.","cause":"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.","error":"TypeError: this._bytes is not a function"},{"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.","cause":"Attempting to `require('stream-parser')` from an ECMAScript Module (ESM) context in Node.js, which is not directly supported by this CommonJS-only package.","error":"ERR_REQUIRE_ESM"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/TooTallNate/node-stream-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stream-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}