{
  "name": "union",
  "description": "A hybrid buffered / streaming middleware kernel backwards compatible with connect.",
  "version": "0.3.8",
  "author": {
    "name": "Nodejitsu Inc.",
    "email": "info@nodejitsu.com"
  },
  "maintainers": [
    {
      "name": "indexzero",
      "email": "charlie@nodejitsu.com"
    },
    {
      "name": "dscape",
      "email": "nuno@nodejitsu.com"
    }
  ],
  "repository": {
    "type": "git",
    "url": "http://github.com/flatiron/union.git"
  },
  "dependencies": {
    "pkginfo": "0.2.x",
    "qs": "0.5.x"
  },
  "devDependencies": {
    "ecstatic": "git://github.com/jesusabdullah/node-ecstatic.git",
    "director": "1.x.x",
    "request": "2.x.x",
    "vows": "0.7.x",
    "connect": "2.3.x"
  },
  "scripts": {
    "test": "vows test/*-test.js --spec -i"
  },
  "main": "./lib",
  "engines": {
    "node": ">= 0.4.0"
  },
  "readme": "\n<img src=\"https://github.com/flatiron/union/raw/master/union.png\" />\n\n# Synopsis\nA hybrid streaming middleware kernel backwards compatible with connect.\n\n# Motivation\nThe advantage to streaming middlewares is that they do not require buffering the entire stream in order to execute their function.\n\n# Status\n\n[![Build Status](https://secure.travis-ci.org/flatiron/union.png)](http://travis-ci.org/flatiron/union)\n\n# Installation\nThere are a few ways to use `union`. Install the library using npm. You can add it to your `package.json` file as a dependancy\n\n```bash\n  $ [sudo] npm install union\n```\n\n## Usage\nUnion's request handling is [connect](https://github.com/senchalabs/connect)-compatible, meaning that all existing connect middlewares should work out-of-the-box with union.\n\n**(Union 0.3.x is compatible with connect >= 2.1.0, [Extensively Tested](https://github.com/pksunkara/connect-union))**\n\nIn addition, the response object passed to middlewares listens for a \"next\" event, which is equivalent to calling `next()`. Flatiron middlewares are written in this manner, meaning they are not reverse-compatible with connect.\n\n### A simple case\n\n``` js\nvar fs = require('fs'),\n    union = require('../lib'),\n    director = require('director');\n\nvar router = new director.http.Router();\n\nvar server = union.createServer({\n  before: [\n    function (req, res) {\n      var found = router.dispatch(req, res);\n      if (!found) {\n        res.emit('next');\n      }\n    }\n  ]\n});\n\nrouter.get(/foo/, function () {\n  this.res.writeHead(200, { 'Content-Type': 'text/plain' })\n  this.res.end('hello world\\n');\n});\n\nrouter.post(/foo/, { stream: true }, function () {\n  var req = this.req,\n      res = this.res,\n      writeStream;\n\n  writeStream = fs.createWriteStream(Date.now() + '-foo.txt');\n  req.pipe(writeStream);\n\n  writeStream.on('close', function () {\n    res.writeHead(200, { 'Content-Type': 'text/plain' });\n    res.end('wrote to a stream!');\n  });\n});\n\nserver.listen(9090);\nconsole.log('union with director running on 9090');\n```\n\nTo demonstrate the code, we use [director](https://github.com/flatiron/director). A light-weight, Client AND Server side URL-Router for Node.js and Single Page Apps!\n\n### A case with connect\n\nCode based on connect\n\n```js\nvar connect = require('connect')\n  , http = require('http');\n\nvar app = connect()\n  .use(connect.favicon())\n  .use(connect.logger('dev'))\n  .use(connect.static('public'))\n  .use(connect.directory('public'))\n  .use(connect.cookieParser('my secret here'))\n  .use(connect.session())\n  .use(function (req, res) {\n    res.end('Hello from Connect!\\n');\n  });\n\nhttp.createServer(app).listen(3000);\n```\n\nCode based on union\n\n```js\nvar connect = require('connect')\n  , union = require('union');\n\nvar server = union.createServer({\n  buffer: false,\n  before: [\n    connect.favicon(),\n    connect.logger('dev'),\n    connect.static('public'),\n    connect.directory('public'),\n    connect.cookieParser('my secret here'),\n    connect.session(),\n    function (req, res) {\n      res.end('Hello from Connect!\\n');\n    },\n  ]\n}).listen(3000);\n```\n\n### SPDY enabled server example\n\n# API\n\n## union Static Members\n\n### createServer(options)\nThe `options` object is required. Options include:\n\nSpecification\n\n```\n  function createServer(options)\n\n  @param options {Object}\n  An object literal that represents the configuration for the server.\n\n    @option before {Array}\n    The `before` value is an array of middlewares, which are used to route and serve incoming\n    requests. For instance, in the example, `favicon` is a middleware which handles requests\n    for `/favicon.ico`.\n\n    @option after {Array}\n    The `after` value is an array of functions that return stream filters,\n    which are applied after the request handlers in `options.before`.\n    Stream filters inherit from `union.ResponseStream`, which implements the\n    Node.js core streams api with a bunch of other goodies.\n\n    @option limit {Object}\n    (optional) A value, passed to internal instantiations of `union.BufferedStream`.\n\n    @option https {Object}\n    (optional) A value that specifies the certificate and key necessary to create an instance of\n    `https.Server`.\n\n    @option spdy {Object}\n    (optional) A value that specifies the certificate and key necessary to create an instance of\n    `spdy.Server`.\n\n    @option headers {Object}\n    (optional) An object representing a set of headers to set in every outgoing response\n```\n\nExample\n\n```js\nvar server = union.createServer({\n  before: [\n    favicon('./favicon.png'),\n    function (req, res) {\n      var found = router.dispatch(req, res);\n      if (!found) {\n        res.emit('next');\n      }\n    }\n  ]\n});\n```\n\nAn example of the `https` or `spdy` option.\n\n``` js\n{\n  cert: 'path/to/cert.pem',\n  key: 'path/to/key.pem',\n  ca: 'path/to/ca.pem'\n}\n```\n\nAn example of the `headers` option.\n\n``` js\n{\n  'x-powered-by': 'your-sweet-application v10.9.8'\n}\n```\n\n## Error Handling\nError handler is similiar to middlware but takes an extra argument for error at the beginning.\n\n```js\nvar handle = function (err, req, res) {\n  res.statusCode = err.status;\n  res.end(req.headers);\n};\n\nvar server = union.createServer({\n  onError: handle,\n  before: [\n    favicon('./favicon.png'),\n    function (req, res) {\n      var found = router.dispatch(req, res);\n      if (!found) {\n        res.emit('next');\n      }\n    }\n  ]\n});\n```\n\n## BufferedStream Constructor\nThis constructor inherits from `Stream` and can buffer data up to `limit` bytes. It also implements `pause` and `resume` methods.\n\nSpecification\n\n```\n  function BufferedStream(limit)\n\n  @param limit {Number}\n  the limit for which the stream can be buffered\n```\n\nExample\n\n```js\nvar bs = union.BufferedStream(n);\n```\n\n## HttpStream Constructor\nThis constructor inherits from `union.BufferedStream` and returns a stream with these extra properties:\n\nSpecification\n\n```\n  function HttpStream()\n```\n\nExample\n\n```js\nvar hs = union.HttpStream();\n```\n\n## HttpStream Instance Members\n\n### url\nThe url from the request.\n\nExample\n\n```js\nhttpStream.url = '';\n```\n\n### headers\nThe HTTP headers associated with the stream.\n\nExample\n\n```js\nhttpStream.headers = '';\n```\n\n### method\nThe HTTP method (\"GET\", \"POST\", etc).\n\nExample\n\n```js\nhttpStream.method = 'POST';\n```\n\n### query\nThe querystring associated with the stream (if applicable).\n\nExample\n\n```js\nhttpStream.query = '';\n```\n\n## ResponseStream Constructor\nThis constructor inherits from `union.HttpStream`, and is additionally writeable. Union supplies this constructor as a basic response stream middleware from which to inherit.\n\nSpecification\n\n```\n  function ResponseStream()\n```\n\nExample\n\n```js\nvar rs = union.ResponseStream();\n```\n\n# Tests\n\nAll tests are written with [vows][0] and should be run with [npm][1]:\n\n``` bash\n  $ npm test\n```\n\n# Licence\n\n(The MIT License)\n\nCopyright (c) 2010-2012 Nodejitsu Inc. <http://www.twitter.com/nodejitsu>\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n\n[0]: http://vowsjs.org\n[1]: http://npmjs.org\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/flatiron/union/issues"
  },
  "homepage": "https://github.com/flatiron/union",
  "_id": "union@0.3.8",
  "_shasum": "26a702a4d3528b4358c9711c8abff6cc91d24257",
  "_from": "union@0.3.x",
  "_resolved": "https://registry.npmjs.org/union/-/union-0.3.8.tgz"
}
