{"dist":{"shasum":"8ad9a58ca9e08729e2cef7d299b25a8436eb7cbb","tarball":"https://registry.npmjs.org/bufferstream/-/bufferstream-0.5.0-pre2.tgz","integrity":"sha512-3e+9Zet8/S3oGdw4gD8L1Bewih28tTc9AB9GdhzVElm5vrotsiltBw+D0NRxxsDC9xjbG/lbpTyzNPErJkM55g==","signatures":[{"sig":"MEYCIQDzRCg+0En/CQK7CyKopFmblYB1VvkyaQv0g/Mu4hB8HgIhAMJqwS/82DVcRTYuPJ8fqit11cjy/O0M6h0wCoAcfSv4","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"bufferstream.js","name":"bufferstream","author":{"url":"https://github.com/dodo","name":"dodo"},"readme":"# BufferStream\n\npainless stream buffering, cutting and piping.\n\n## install\n\n    npm install bufferstream\n\n## api\n\nBufferStream is a full node.js [Stream](http://nodejs.org/docs/v0.4.7/api/streams.html) so it has apis of both [Writeable Stream](http://nodejs.org/docs/v0.4.7/api/streams.html#writable_Stream) and [Readable Stream](http://nodejs.org/docs/v0.4.7/api/streams.html#readable_Stream).\n\n### BufferStream\n\n```javascript\nBufferStream = require('bufferstream')\nstream = new BufferStream([{encoding:'utf8', size:'none'}]) // default\n```\n * `encoding` default encoding for writing strings\n * `size` defines buffer level or sets buffer to given size (see ↓`setSize` for more)\n * `disabled` immediately call disable\n * `split` short form for:\n\n```javascript\nstream.split(token, function (chunk) {stream.emit('data', chunk)})\n```\n\n### stream.setSize\n\n```javascript\nstream.setSize(size) // can be one of ['none', 'flexible', <number>]\n```\n\ndifferent buffer behaviors can be triggered by size:\n\n * `none` when output drains, bufferstream drains too\n * `flexible` buffers everthing that it gets and not piping out\n * `<number>` `TODO` buffer has given size. buffers everthing until buffer is full. when buffer is full then  the stream will drain\n\n### stream.enable\n\n```javascript\nstream.enable()\n```\n\nenables stream buffering __default__\n\n### stream.disable\n\n```javascript\nstream.disable()\n```\n\nflushes buffer and disables stream buffering.\nBufferStream now pipes all data as long as the output accepting data.\nwhen the output is draining BufferStream will buffer all input temporary.\n\n```javascript\nstream.disable(token, ...)\nstream.disable(tokens) // Array\n```\n * `token[s]` buffer splitters (should be String or Buffer)\n\ndisables given tokens. wont flush until no splitter tokens are left.\n\n### stream.split\n\n```javascript\nstream.split(token, ...)\nstream.split(tokens) // Array\n```\n * `token[s]` buffer splitters (should be String or Buffer)\n\neach time BufferStream finds a splitter token in the input data it will emit a __split__ event.\nthis also works for binary data.\n\n### Event: 'split'\n\n```javascript\nstream.on('split', function (chunk, token) {…})\nstream.split(token, function (chunk, token) {…}) // only get called for this particular token\n```\n\nwhenever the stream is enabled it will try to find all splitter token in `stream.buffer`,\ncut it off and emit the chunk (without token) as __split__ event.\nthis data will be lost when not handled.\n\nthe chunk is the cut off of `stream.buffer` without the token.\n\n__Warning:__ try to avoid calling `stream.emit('data', newchunk)` more than one time, because this will likely throw `Error: Offset is out of bounds`.\n\n### stream.getBuffer\n\n```javascript\nstream.getBuffer()\n// or just\nstream.buffer\n```\n\nreturns its [Buffer](http://nodejs.org/docs/v0.4.7/api/buffers.html).\n\n### stream.toString\n\n```javascript\nstream.toString()\n```\n\nshortcut for `stream.buffer.toString()`\n\n### stream.length\n\n```javascript\nstream.length\n```\n\nshortcut for `stream.buffer.length`\n\n### PostBuffer\n\n```javascript\nPostBuffer = require('bufferstream/postbuffer')\npost = new PostBuffer(req)\n```\n * `req` http.ServerRequest\n\nfor if you want to get all the post data from a http server request and do some db reqeust before.\n\nbuffer http client\n\n### post.onEnd\n\n```javascript\npost.onEnd(function (data) {…});\n```\n\nset a callback to get all post data from a http server request\n\n### post.pipe\n\n```javascript\npost.pipe(stream, options);\n```\n\npumps data into another stream to allow incoming streams\ngiven options will be passed to Stream.pipe\n\n## example\n\n```javascript\nBufferStream = require('bufferstream')\nstream = new BufferStream({encoding:'utf8', size:'flexible'})\nstream.split('//', ':')\nstream.on('split', function (chunk, token) {\n    console.log(\"got '%s' by '%s'\", chunk.toString(), token.toString())\n})\nstream.write(\"buffer:stream//23\")\nconsole.log(stream.toString())\n```\n\nresults in\n\n    got 'buffer' by ':'\n    got 'stream' by '//'\n    23\n\n* https://github.com/dodo/node-bufferstream/blob/master/example/split.js\n\n## FAQ\n\n> I'm not sure from your readme what the split event emits?\n\nyou can specify more than one split token .. so it's emitted whenever\na token is found.\n\n> does it emit the buffer up to the just before the token starts?\n\nyes.\n\n> also, does it join buffers together if they do not already end in a token?\n\nwhen size is `flexible` it joins everything together what it gets to\none buffer (accessible through `stream.buffer` or\n`stream.getBuffer()`)\nwhenever it gets data, it will try to find all tokens\n\n> in other words, can I use this to rechunk a stream so that the chunks always break on newlines, for example?\n\nyes.\n\n```javascript\nstream = new BufferStream({size:'flexible'});\nstream.split('\\n', function (line) { // line doesn't have a '\\n' anymore\n    stream.emit('data', line); // Buffer.isBuffer(line) === true\n});\n```\n\n[![Build Status](https://secure.travis-ci.org/dodo/node-bufferstream.png)](http://travis-ci.org/dodo/node-bufferstream)\n","engines":{"node":">= 0.4.x"},"scripts":{"test":"cake build && nodeunit test","prepublish":"cake build"},"_npmUser":{"name":"dodo","email":"dodo@blacksec.org"},"homepage":"https://github.com/dodo/node-bufferstream","keywords":["buffer","buffers","stream","streams"],"repository":{"url":"git://github.com/dodo/node-bufferstream.git","type":"git"},"_npmVersion":"1.1.0-beta-10","description":"painless stream buffering and cutting","directories":{},"maintainers":[{"name":"dodo","email":"dodo@blacksec.org"}],"_nodeVersion":"v0.6.7","dependencies":{"buffertools":">= 1.0.3","valvestream":">= 0.0.1"},"_defaultsLoaded":true,"devDependencies":{"cli":">= 0.3.7","muffin":">= 0.2.6","express":">= 2.4.5","nodeunit":">= 0.5.4","coffee-script":">= 1.1.2"},"_engineSupported":true,"_id":"bufferstream@0.5.0-pre2","version":"0.5.0-pre2"}