0.2.0 • Published 11 years ago

stream-simple v0.2.0

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

#stream-simple

This project is an util for converting node readable streams to simple-stream format suggested by Tim Caswell.

##Example

http echo server

var Simple = require('stream-simple')
var http = require('http')

http.createServer(function(req, res) {
  var body = Simple(req)

  res.on('error', function() {
    body.abort()
  })

  res.writeHead(200, {
    'Content-Type': req.headers['content-type']
  })

  ;(function read() {
    body.read(function(err, chunk) {
      if (err) return res.destroy()
      if (!chunk) return res.end()
      res.write(chunk)
      read()
    })
  })()
})

##Installation

via npm

npm install stream-simple

##License

MIT