{"_id":"throughout","_rev":"8-e8d080c107a46158b0e4ee18141597f4","name":"throughout","description":"apply a through stream to the output side of another through stream","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"throughout","version":"0.0.0","description":"apply a through stream to the output side of another through stream","main":"index.js","dependencies":{"through":"~2.3.4","duplexer":"~0.0.2"},"devDependencies":{"tap":"~0.4.3","tape":"~1.0.2","concat-stream":"~0.1.1"},"scripts":{"test":"tap test/*.js"},"testling":{"files":"test/*.js","browsers":["ie/6..latest","chrome/20..latest","firefox/10..latest","safari/latest","opera/11.0..latest","iphone/6","ipad/6"]},"repository":{"type":"git","url":"git://github.com/substack/throughout.git"},"homepage":"https://github.com/substack/throughout","keywords":["through","stream","filter","resume"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","readme":"# throughout\n\nApply a through stream to the output side of another through stream,\npreserving the first stream as input in the returned stream.\n\n[![build status](https://secure.travis-ci.org/substack/throughout.png)](http://travis-ci.org/substack/throughout)\n\n[![browser support](https://ci.testling.com/substack/throughout.png)](http://ci.testling.com/substack/throughout)\n\n# example\n\n``` js\nvar through = require('through');\nvar throughout = require('throughput');\n\nvar doubler = through(function (buf) {\n    var dbuf = new Buffer(buf.length * 2);\n    for (var i = 0; i < dbuf.length; i++) {\n        dbuf[i] = buf[Math.floor(i/2)];\n    }\n    this.queue(dbuf);\n});\n\nvar counter = through(\n    function (buf) {\n        this._count = (this._count || 0) + buf.length;\n    },\n    function () {\n        this.queue(this._count + '\\n');\n        this.queue(null);\n    }\n);\n\nprocess.stdin\n    .pipe(throughout(doubler, counter))\n    .pipe(process.stdout)\n;\n```\n\n# rationale\n\nIf you want to transform just the output side of a through stream, this is\nactually somewhat difficult and it's not immediately obvious why something like:\n\n``` js\nvar duplexer = require('duplexer');\n\nfunction filterOutput (a, b) {\n    a.pipe(b);\n    return duplexer(a, b);\n}\n```\n\nshouldn't just work. The worst part is that it *does* work, until you try to\npipe the results to a slow endpoint that will throttle with pause and resume.\n\nThe problem is that both `duplexer` and `.pipe()` will handle pause and resume\nin a mutually exclusive way that will cause the stream to hang indefinitely if a\nslow downstream consumer ever triggers a pause.\n\nIf you try to use event-stream's .pipeline() function you will get the same\nproblem.\n\n# methods\n\n``` js\nvar throughout = require('throughout');\n```\n\n## var c = throughout(a, b)\n\nPipe the output of a through stream `a` into the input of a through stream `b`,\nreturning a new stream `c` that writes its input to `a` and forwards the output\nfrom `b`.\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install throughout\n```\n\n# license\n\nMIT\n","readmeFilename":"readme.markdown","_id":"throughout@0.0.0","dist":{"shasum":"da935527231a7944daa60d3ad47a32429af1a8c1","tarball":"https://registry.npmjs.org/throughout/-/throughout-0.0.0.tgz","integrity":"sha512-WOr85Dpe0ordFnWwbtUmv/vfENqNFKlOou9UaRzbtAJcnh2GqBQZyclBUij/yRLRc96CxTIbhmLaIchHAmUpJg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDcWCR3R6TFuj2jXeL258ptRwhFDQauL+a+Dsik6qrsoAIhAJrMI68aYEGemlLolQq9Sh8MIbK2KVeHzKvHLi9XjRX6"}]},"_from":".","_npmVersion":"1.2.2","_npmUser":{"name":"substack","email":"mail@substack.net"},"maintainers":[{"name":"substack","email":"mail@substack.net"}],"directories":{}}},"readme":"# throughout\n\nApply a through stream to the output side of another through stream,\npreserving the first stream as input in the returned stream.\n\n[![build status](https://secure.travis-ci.org/substack/throughout.png)](http://travis-ci.org/substack/throughout)\n\n[![browser support](https://ci.testling.com/substack/throughout.png)](http://ci.testling.com/substack/throughout)\n\n# example\n\n``` js\nvar through = require('through');\nvar throughout = require('throughput');\n\nvar doubler = through(function (buf) {\n    var dbuf = new Buffer(buf.length * 2);\n    for (var i = 0; i < dbuf.length; i++) {\n        dbuf[i] = buf[Math.floor(i/2)];\n    }\n    this.queue(dbuf);\n});\n\nvar counter = through(\n    function (buf) {\n        this._count = (this._count || 0) + buf.length;\n    },\n    function () {\n        this.queue(this._count + '\\n');\n        this.queue(null);\n    }\n);\n\nprocess.stdin\n    .pipe(throughout(doubler, counter))\n    .pipe(process.stdout)\n;\n```\n\n# rationale\n\nIf you want to transform just the output side of a through stream, this is\nactually somewhat difficult and it's not immediately obvious why something like:\n\n``` js\nvar duplexer = require('duplexer');\n\nfunction filterOutput (a, b) {\n    a.pipe(b);\n    return duplexer(a, b);\n}\n```\n\nshouldn't just work. The worst part is that it *does* work, until you try to\npipe the results to a slow endpoint that will throttle with pause and resume.\n\nThe problem is that both `duplexer` and `.pipe()` will handle pause and resume\nin a mutually exclusive way that will cause the stream to hang indefinitely if a\nslow downstream consumer ever triggers a pause.\n\nIf you try to use event-stream's .pipeline() function you will get the same\nproblem.\n\n# methods\n\n``` js\nvar throughout = require('throughout');\n```\n\n## var c = throughout(a, b)\n\nPipe the output of a through stream `a` into the input of a through stream `b`,\nreturning a new stream `c` that writes its input to `a` and forwards the output\nfrom `b`.\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install throughout\n```\n\n# license\n\nMIT\n","maintainers":[{"email":"nopersonsmodules@gmail.com","name":"nopersonsmodules"}],"time":{"modified":"2022-11-08T10:41:19.795Z","created":"2013-05-20T04:07:47.113Z","0.0.0":"2013-05-20T04:07:48.357Z"},"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"repository":{"type":"git","url":"git://github.com/substack/throughout.git"},"users":{"regular":true}}