Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Nov 24, 2011
1 parent 9408a3a commit 0a4d7f4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# mw-pipes

connect-compatible middleware connector, but with more elegant support for streams.

allow better support for streams that modify the request or response.

``` js
var pipes = require('mw-pipes')
, http = require('http')

http.createServer(
pipes(
function (req, res, next) {
var x = new XStream()
var y = new YStream()

req.pipe(x)
y.pipe(y)

next(null, x, y)
},
...
```
the properties of `req` and `res` will be copied onto x and y with getters/setters so that
they will behave just like a regular `ServerRequest` and `ServerResponse` to downstream middleware.
## Example
the following would fail using `connect`
``` js
var http = require('http')
, pipes = require('mw-pipes')
, BufferedStream = require('morestreams').BufferedStream
;

http.createServer(pipes(
function (req, res, next) {
var b = new BufferedStream()
req.pipe(b)
// replace the req stream with a buffered stream.
// data events will be buffered until the pipe method is called.
next(null, b)
},
function (req, res, next) {
// this wouldn't work with connect.
// the data events would get lost,
setTimeout(function () {
res.writeHeader(202)
req.pipe(res)
}, 1000)
}
)).listen(8080)
```

0 comments on commit 0a4d7f4

Please sign in to comment.