{"_id":"stream-parser","_rev":"373451","name":"stream-parser","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","dist-tags":{"latest":"0.3.1"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"time":{"modified":"2021-07-27T06:35:33.000Z","created":"2013-02-05T22:00:19.953Z","0.3.1":"2015-06-04T16:40:47.842Z","0.3.0":"2014-06-22T16:58:41.951Z","0.2.0":"2014-06-21T19:13:25.198Z","0.1.2":"2014-06-16T19:47:18.335Z","0.1.1":"2014-06-16T18:28:15.773Z","0.1.0":"2013-07-05T05:25:47.625Z","0.0.5":"2013-03-07T08:21:48.993Z","0.0.4":"2013-02-24T01:52:58.404Z","0.0.3":"2013-02-11T01:40:15.441Z","0.0.2":"2013-02-08T22:37:31.422Z","0.0.1":"2013-02-05T22:00:19.953Z"},"users":{},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"versions":{"0.3.1":{"name":"stream-parser","version":"0.3.1","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"index.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"2"},"devDependencies":{"mocha":"*","readable-stream":"1.0"},"gitHead":"a0e021b9757be0dce764b7f60e23dd678b05f12f","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"homepage":"https://github.com/TooTallNate/node-stream-parser#readme","_id":"stream-parser@0.3.1","_shasum":"1618548694420021a1182ff0af1911c129761773","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"1618548694420021a1182ff0af1911c129761773","size":7363,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.3.1.tgz"},"directories":{},"publish_time":1433436047842,"_cnpm_publish_time":1433436047842,"_hasShrinkwrap":false},"0.3.0":{"name":"stream-parser","version":"0.3.0","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"index.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~1.0.0"},"devDependencies":{"mocha":"*","readable-stream":"1.0"},"gitHead":"f921decd512db1d8f6226ff67a2b7d66816c1548","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"homepage":"https://github.com/TooTallNate/node-stream-parser","_id":"stream-parser@0.3.0","_shasum":"6c71d18c81994424bead288e14bfbb6389e81fa8","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"6c71d18c81994424bead288e14bfbb6389e81fa8","size":7374,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.3.0.tgz"},"directories":{},"publish_time":1403456321951,"_cnpm_publish_time":1403456321951,"_hasShrinkwrap":false},"0.2.0":{"name":"stream-parser","version":"0.2.0","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"index.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~1.0.0"},"devDependencies":{"mocha":"*","readable-stream":"1.0"},"gitHead":"1541cdac56d4122ef1a57e6a13f7e84c49272e5c","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"homepage":"https://github.com/TooTallNate/node-stream-parser","_id":"stream-parser@0.2.0","_shasum":"89ff6563203a8acf11ead9e53207725de7f77ef9","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"89ff6563203a8acf11ead9e53207725de7f77ef9","size":7052,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.2.0.tgz"},"directories":{},"publish_time":1403378005198,"_cnpm_publish_time":1403378005198,"_hasShrinkwrap":false},"0.1.2":{"name":"stream-parser","version":"0.1.2","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~1.0.0"},"devDependencies":{"mocha":"*","readable-stream":"1.0"},"gitHead":"24f828054383065c9bd8f9bffc7cffb0b637b6ce","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"homepage":"https://github.com/TooTallNate/node-stream-parser","_id":"stream-parser@0.1.2","_shasum":"c665e8aaf43d13f477bfb0722939584b9f023e72","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"c665e8aaf43d13f477bfb0722939584b9f023e72","size":6886,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.1.2.tgz"},"directories":{},"publish_time":1402948038335,"_cnpm_publish_time":1402948038335,"_hasShrinkwrap":false},"0.1.1":{"name":"stream-parser","version":"0.1.1","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~1.0.0"},"devDependencies":{"mocha":"*","readable-stream":"1.0"},"gitHead":"116aca91f345cecef96a67f332badda5984cb487","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"homepage":"https://github.com/TooTallNate/node-stream-parser","_id":"stream-parser@0.1.1","_shasum":"1770b7ae7351d06f8d8286bbcbf28034222414c5","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"dist":{"shasum":"1770b7ae7351d06f8d8286bbcbf28034222414c5","size":6862,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.1.1.tgz"},"directories":{},"publish_time":1402943295773,"_cnpm_publish_time":1402943295773,"_hasShrinkwrap":false},"0.1.0":{"name":"stream-parser","version":"0.1.0","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~0.7.0"},"devDependencies":{"mocha":"*","readable-stream":"*"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"_id":"stream-parser@0.1.0","dist":{"shasum":"c4f4c5483ee545d8ca2b39babc3ab74255062bf8","size":6823,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.1.0.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1373001947625,"_cnpm_publish_time":1373001947625,"_hasShrinkwrap":false},"0.0.5":{"name":"stream-parser","version":"0.0.5","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~0.7.0"},"devDependencies":{"mocha":"*","readable-stream":"*"},"readmeFilename":"README.md","_id":"stream-parser@0.0.5","dist":{"shasum":"3da94809f42eaaaf42ade8124ac62762ce9ea531","size":5838,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.0.5.tgz"},"_from":".","_npmVersion":"1.2.12","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1362644508993,"_cnpm_publish_time":1362644508993,"_hasShrinkwrap":false},"0.0.4":{"name":"stream-parser","version":"0.0.4","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~0.7.0"},"devDependencies":{"mocha":"*","readable-stream":"*"},"readmeFilename":"README.md","_id":"stream-parser@0.0.4","dist":{"shasum":"a28a9877364bf0c7f8d14f7fe297387035c737e4","size":5675,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.0.4.tgz"},"_from":".","_npmVersion":"1.2.12","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1361670778404,"_cnpm_publish_time":1361670778404,"_hasShrinkwrap":false},"0.0.3":{"name":"stream-parser","version":"0.0.3","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~0.7.0"},"devDependencies":{"mocha":"*","readable-stream":"*"},"readmeFilename":"README.md","_id":"stream-parser@0.0.3","dist":{"shasum":"a80ccdecf0189794a3ac4e0a0af7e3a633fa8b80","size":5518,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.0.3.tgz"},"_from":".","_npmVersion":"1.2.10","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1360546815441,"_cnpm_publish_time":1360546815441,"_hasShrinkwrap":false},"0.0.2":{"name":"stream-parser","version":"0.0.2","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~0.7.0"},"devDependencies":{"mocha":"*","readable-stream":"*"},"readmeFilename":"README.md","_id":"stream-parser@0.0.2","dist":{"shasum":"f145e5b0997c7a4fc31bfc8949e315fb617e1992","size":4629,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.0.2.tgz"},"_from":".","_npmVersion":"1.2.10","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1360363051422,"_cnpm_publish_time":1360363051422,"_hasShrinkwrap":false},"0.0.1":{"name":"stream-parser","version":"0.0.1","description":"Generic interruptible \"parser\" mixin for Transform & Writable streams","main":"lib/parser.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git://github.com/TooTallNate/node-stream-parser.git"},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"license":"MIT","dependencies":{"debug":"~0.7.0"},"devDependencies":{"mocha":"*"},"readmeFilename":"README.md","_id":"stream-parser@0.0.1","dist":{"shasum":"a208dabdc5a222e5ac16ab0cbbb2fa67c5bb5dd9","size":4082,"noattachment":false,"key":"/stream-parser/-/stream-parser-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/stream-parser/download/stream-parser-0.0.1.tgz"},"_from":".","_npmVersion":"1.2.3","_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1360101619953,"_cnpm_publish_time":1360101619953,"_hasShrinkwrap":false}},"readme":"node-stream-parser\n==================\n### Generic interruptible \"parser\" mixin for Transform & Writable streams\n[![Build Status](https://secure.travis-ci.org/TooTallNate/node-stream-parser.svg)](http://travis-ci.org/TooTallNate/node-stream-parser)\n\nThis module offers the `stream-parser` mixin, which provides an easy-to-use API\nfor parsing bytes from `Writable` and/or `Transform` stream instances. This module\nis great for implementing streaming parsers for standardized file formats.\n\nFor `Writable` streams, the parser takes control over the `_write` callback\nfunction. For `Transform` streams, the parser controls the `_transform` callback\nfunction.\n\nInstallation\n------------\n\n``` bash\n$ npm install stream-parser\n```\n\n\nExample\n-------\n\nLet's create a quick `Transform` stream subclass that utilizes the parser's\n`_bytes()` and `_passthrough()` functions to parse a theoretical file format that\nhas an 8-byte header we want to parse, and then pass through the rest of the data.\n\n``` javascript\nvar Parser = require('stream-parser');\nvar inherits = require('util').inherits;\nvar Transform = require('stream').Transform;\n\n// create a Transform stream subclass\nfunction MyParser () {\n  Transform.call(this);\n\n  // buffer the first 8 bytes written\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, output) {\n  // parse the \"buffer\" into a useful \"header\" object\n  var header = {};\n  header.type = buffer.readUInt32LE(0);\n  header.name = buffer.toString('utf8', 4);\n  this.emit('header', header);\n\n  // it's usually a good idea to queue the next \"piece\" within the callback\n  this._passthrough(Infinity);\n};\n\n\n// now we can *use* it!\nvar parser = new MyParser();\nparser.on('header', function (header) {\n  console.error('got \"header\"', header);\n});\nprocess.stdin.pipe(parser).pipe(process.stdout);\n```\n\nHere's an example of manually creating a `Transform` stream and turning it into a\n\"pass through\" stream equivalent to the one built into node core:\n\n``` javascript\nvar Parser = require('stream-parser');\nvar Transform = require('stream').Transform;\n\n// create a Transform instance and extend it with \"stream-parser\"\nvar p = new Transform();\nParser(p);\n\n// pass through `Infinity` bytes... forever...\np._passthrough(Infinity);\n\n// now `p` is equivalent to a stream.PassThrough instance\nprocess.stdin.pipe(p).pipe(process.stdout);\n```\n\nSee the `test` directory for some more example code in the test cases.\n\nA list of known concrete implementations is here (send pull requests for more!):\n\n * [node-icecast][]\n * [node-throttle][]\n * [node-flv][]\n * [node-wav][]\n\nAPI\n---\n\n  - [Parser()](#parser)\n    - [._bytes(n, cb)](#_bytesn-cb)\n    - [._skipBytes(n, cb)](#_skipbytesn-cb)\n    - [._passthrough(n, cb)](#_passthroughn-cb)\n\n## Parser()\n\n  The `Parser` stream mixin works with either `Writable` or `Transform` stream\n  instances/subclasses. Provides a convenient generic \"parsing\" API:\n\n```js\n_bytes(n, cb) - buffers \"n\" bytes and then calls \"cb\" with the \"chunk\"\n_skipBytes(n, cb) - skips \"n\" bytes and then calls \"cb\" when done\n```\n\n  If you extend a `Transform` stream, then the `_passthrough()` function is also\n  added:\n\n```js\n_passthrough(n, cb) - passes through \"n\" bytes untouched and then calls \"cb\"\n```\n\n### ._bytes(n, cb)\n\n  Buffers `n` bytes and then invokes `cb` once that amount has been collected.\n\n### ._skipBytes(n, cb)\n\n  Skips over the next `n` bytes and then invokes `cb` once that amount has been\n  discarded.\n\n### ._passthrough(n, cb)\n\n  Passes through `n` bytes to the readable side of this stream untouched,\n  then invokes `cb` once that amount has been passed through. This function is only defined\n  when stream-parser is extending a `Transform` stream.\n\n[node-icecast]: https://github.com/TooTallNate/node-icecast\n[node-throttle]: https://github.com/TooTallNate/node-throttle\n[node-flv]: https://github.com/TooTallNate/node-flv\n[node-wav]: https://github.com/TooTallNate/node-wav\n","_attachments":{},"homepage":"https://github.com/TooTallNate/node-stream-parser#readme","bugs":{"url":"https://github.com/TooTallNate/node-stream-parser/issues"},"license":"MIT"}