pax_global_header00006660000000000000000000000064121365357040014520gustar00rootroot0000000000000052 comment=e9b1c46e6b0b00f1a92bf2a30f7521516686ce83 duplexer-0.1.1/000077500000000000000000000000001213653570400133475ustar00rootroot00000000000000duplexer-0.1.1/.gitignore000066400000000000000000000000301213653570400153300ustar00rootroot00000000000000node_modules *.log *.errduplexer-0.1.1/.travis.yml000066400000000000000000000001051213653570400154540ustar00rootroot00000000000000language: node_js node_js: - "0.11" - "0.10" - "0.8" - "0.6" duplexer-0.1.1/LICENCE000066400000000000000000000020321213653570400143310ustar00rootroot00000000000000Copyright (c) 2012 Raynos. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.duplexer-0.1.1/README.md000066400000000000000000000017001213653570400146240ustar00rootroot00000000000000# duplexer [![build status][1]][2] [![dependency status][3]][4] [![browser support][5]][6] Creates a duplex stream Taken from [event-stream][7] ## duplex (writeStream, readStream) Takes a writable stream and a readable stream and makes them appear as a readable writable stream. It is assumed that the two streams are connected to each other in some way. ## Example ```js var grep = cp.exec('grep Stream') duplex(grep.stdin, grep.stdout) ``` ## Installation `npm install duplexer` ## Tests `npm test` ## Contributors - Dominictarr - Raynos - samccone ## MIT Licenced [1]: https://secure.travis-ci.org/Raynos/duplexer.png [2]: https://travis-ci.org/Raynos/duplexer [3]: https://david-dm.org/Raynos/duplexer.png [4]: https://david-dm.org/Raynos/duplexer [5]: https://ci.testling.com/Raynos/duplexer.png [6]: https://ci.testling.com/Raynos/duplexer [7]: https://github.com/dominictarr/event-stream#duplex-writestream-readstream duplexer-0.1.1/index.js000066400000000000000000000035341213653570400150210ustar00rootroot00000000000000var Stream = require("stream") var writeMethods = ["write", "end", "destroy"] var readMethods = ["resume", "pause"] var readEvents = ["data", "close"] var slice = Array.prototype.slice module.exports = duplex function forEach (arr, fn) { if (arr.forEach) { return arr.forEach(fn) } for (var i = 0; i < arr.length; i++) { fn(arr[i], i) } } function duplex(writer, reader) { var stream = new Stream() var ended = false forEach(writeMethods, proxyWriter) forEach(readMethods, proxyReader) forEach(readEvents, proxyStream) reader.on("end", handleEnd) writer.on("drain", function() { stream.emit("drain") }) writer.on("error", reemit) reader.on("error", reemit) stream.writable = writer.writable stream.readable = reader.readable return stream function proxyWriter(methodName) { stream[methodName] = method function method() { return writer[methodName].apply(writer, arguments) } } function proxyReader(methodName) { stream[methodName] = method function method() { stream.emit(methodName) var func = reader[methodName] if (func) { return func.apply(reader, arguments) } reader.emit(methodName) } } function proxyStream(methodName) { reader.on(methodName, reemit) function reemit() { var args = slice.call(arguments) args.unshift(methodName) stream.emit.apply(stream, args) } } function handleEnd() { if (ended) { return } ended = true var args = slice.call(arguments) args.unshift("end") stream.emit.apply(stream, args) } function reemit(err) { stream.emit("error", err) } } duplexer-0.1.1/package.json000066400000000000000000000017711213653570400156430ustar00rootroot00000000000000{ "name": "duplexer", "version": "0.1.1", "description": "Creates a duplex stream", "keywords": [], "author": "Raynos ", "repository": "git://github.com/Raynos/duplexer.git", "main": "index", "homepage": "https://github.com/Raynos/duplexer", "contributors": [ { "name": "Jake Verbaten" } ], "bugs": { "url": "https://github.com/Raynos/duplexer/issues", "email": "raynos2@gmail.com" }, "devDependencies": { "tape": "0.3.3", "through": "~0.1.4" }, "licenses": [ { "type": "MIT", "url": "http://github.com/Raynos/duplexer/raw/master/LICENSE" } ], "scripts": { "test": "node test" }, "testling": { "files": "test/index.js", "browsers": [ "ie/8..latest", "firefox/16..latest", "firefox/nightly", "chrome/22..latest", "chrome/canary", "opera/12..latest", "opera/next", "safari/5.1..latest", "ipad/6.0..latest", "iphone/6.0..latest" ] } } duplexer-0.1.1/test/000077500000000000000000000000001213653570400143265ustar00rootroot00000000000000duplexer-0.1.1/test/index.js000066400000000000000000000010141213653570400157670ustar00rootroot00000000000000var through = require("through") var test = require("tape") var duplex = require("../index") var readable = through() var writable = through(write) var written = 0 var data = 0 var stream = duplex(writable, readable) function write() { written++ } stream.on("data", ondata) function ondata() { data++ } test("emit and write", function(t) { t.plan(2) stream.write() readable.emit("data") t.equal(written, 1, "should have written once") t.equal(data, 1, "should have recived once") })