{
  "name": "finished",
  "description": "Execute a callback when a request closes, finishes, or errors",
  "version": "1.2.2",
  "author": {
    "name": "Jonathan Ong",
    "email": "me@jongleberry.com",
    "url": "http://jongleberry.com"
  },
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git://github.com/expressjs/finished"
  },
  "dependencies": {
    "ee-first": "1.0.3"
  },
  "devDependencies": {
    "istanbul": "0.2.10",
    "mocha": "~1.20.1",
    "should": "~4.0.1"
  },
  "engine": {
    "node": ">= 0.8.0"
  },
  "scripts": {
    "test": "mocha --reporter spec test/",
    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/",
    "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/"
  },
  "readme": "# finished\n\n[![NPM Version](https://badge.fury.io/js/finished.svg)](http://badge.fury.io/js/finished)\n[![Build Status](https://travis-ci.org/expressjs/finished.svg?branch=master)](https://travis-ci.org/expressjs/finished)\n[![Coverage Status](https://img.shields.io/coveralls/expressjs/finished.svg?branch=master)](https://coveralls.io/r/expressjs/finished)\n\nExecute a callback when a request closes, finishes, or errors.\n\n#### Install\n\n```sh\n$ npm install finished\n```\n\n#### Uses\n\nThis is useful for cleaning up streams. For example, you want to destroy any file streams you create on socket errors otherwise you will leak file descriptors.\n\nThis is required to fix what many perceive as issues with node's streams. Relevant:\n\n- [node#6041](https://github.com/joyent/node/issues/6041)\n- [koa#184](https://github.com/koajs/koa/issues/184)\n- [koa#165](https://github.com/koajs/koa/issues/165)\n\n## API\n\n### finished(response, callback)\n\n```js\nvar onFinished = require('finished')\n\nonFinished(res, function (err) {\n  // do something maybe\n})\n```\n\n### Examples\n\nThe following code ensures that file descriptors are always closed once the response finishes.\n\n#### Node / Connect / Express\n\n```js\nvar onFinished = require('finished')\n\nfunction (req, res, next) {\n  var stream = fs.createReadStream('thingie.json')\n  stream.pipe(res)\n  onFinished(res, function (err) {\n    stream.destroy()\n  })\n}\n```\n\n#### Koa\n\n```js\nfunction* () {\n  var stream = this.body = fs.createReadStream('thingie.json')\n  onFinished(this, function (err) {\n    stream.destroy()\n  })\n}\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/expressjs/finished/issues"
  },
  "_id": "finished@1.2.2",
  "_from": "finished@1.2.2"
}
