3 A better `Stream#pipe` that creates duplex streams and lets you handle errors in one place.
5 [![build status](https://secure.travis-ci.org/segmentio/multipipe.png)](http://travis-ci.org/segmentio/multipipe)
10 var pipe = require('multipipe');
13 var stream = pipe(streamA, streamB, streamC);
15 // centralized error handling
16 stream.on('error', fn);
18 // creates a new stream
19 source.pipe(stream).pipe(dest);
21 // optional callback on finish or error
22 pipe(streamA, streamB, streamC, function(err){
29 Write to the pipe and you'll really write to the first stream, read from the pipe and you'll read from the last stream.
32 var stream = pipe(a, b, c);
39 In this example the flow of data is:
49 Each `pipe` forwards the errors the streams it wraps emit, so you have one central place to handle errors:
52 var stream = pipe(a, b, c);
54 stream.on('error', function(err){
58 a.emit('error', new Error);
59 b.emit('error', new Error);
60 c.emit('error', new Error);
67 Pass a variable number of streams and each will be piped to the next one.
69 A stream will be returned that wraps passed in streams in a way that errors will be forwarded and you can write to and/or read from it.
71 Pass a function as last argument to be called on `error` or `finish` of the last stream.
76 $ npm install multipipe
83 Copyright (c) 2014 Segment.io Inc. <friends@segment.io>
84 Copyright (c) 2014 Julian Gruber <julian@juliangruber.com>
86 Permission is hereby granted, free of charge, to any person obtaining a copy
87 of this software and associated documentation files (the "Software"), to deal
88 in the Software without restriction, including without limitation the rights
89 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
90 copies of the Software, and to permit persons to whom the Software is
91 furnished to do so, subject to the following conditions:
93 The above copyright notice and this permission notice shall be included in
94 all copies or substantial portions of the Software.
96 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
101 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN