{
  "name": "on-finished",
  "description": "Execute a callback when a request closes, finishes, or errors",
  "version": "2.1.0",
  "contributors": [
    {
      "name": "Douglas Christopher Wilson",
      "email": "doug@somethingdoug.com"
    },
    {
      "name": "Jonathan Ong",
      "email": "me@jongleberry.com",
      "url": "http://jongleberry.com"
    }
  ],
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git://github.com/jshttp/on-finished"
  },
  "dependencies": {
    "ee-first": "1.0.5"
  },
  "devDependencies": {
    "istanbul": "0.3.0",
    "mocha": "~1.21.4"
  },
  "engine": {
    "node": ">= 0.8.0"
  },
  "files": [
    "HISTORY.md",
    "LICENSE",
    "index.js"
  ],
  "scripts": {
    "test": "mocha --reporter spec --bail --check-leaks test/",
    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
    "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
  },
  "readme": "# on-finished\n\n[![NPM Version](http://img.shields.io/npm/v/on-finished.svg?style=flat)](https://www.npmjs.org/package/on-finished)\n[![Node.js Version](http://img.shields.io/badge/node.js->=_0.8-brightgreen.svg?style=flat)](http://nodejs.org/download/)\n[![Build Status](http://img.shields.io/travis/jshttp/on-finished.svg?style=flat)](https://travis-ci.org/jshttp/on-finished)\n[![Coverage Status](https://img.shields.io/coveralls/jshttp/on-finished.svg?style=flat)](https://coveralls.io/r/jshttp/on-finished)\n\nExecute a callback when a request closes, finishes, or errors.\n\n## Install\n\n```sh\n$ npm install on-finished\n```\n\n## API\n\n```js\nvar onFinished = require('on-finished')\n```\n\n### onFinished(res, listener)\n\nAttach a listener to listen for the response to finish. The listener will\nbe invoked only once when the response finished. If the response finished\nto to an error, the first argument will contain the error.\n\nListening to the end of a response would be used to close things associated\nwith the response, like open files.\n\n```js\nonFinished(res, function (err) {\n  // clean up open fds, etc.\n})\n```\n\n### onFinished(req, listener)\n\nAttach a listener to listen for the request to finish. The listener will\nbe invoked only once when the request finished. If the request finished\nto to an error, the first argument will contain the error.\n\nListening to the end of a request would be used to know when to continue\nafter reading the data.\n\n```js\nvar data = ''\n\nreq.setEncoding('utf8')\nres.on('data', function (str) {\n  data += str\n})\n\nonFinished(req, function (err) {\n  // data is read unless there is err\n})\n```\n\n### onFinished.isFinished(res)\n\nDetermine if `res` is already finished. This would be useful to check and\nnot even start certain operations if the response has already finished.\n\n### onFinished.isFinished(req)\n\nDetermine if `req` is already finished. This would be useful to check and\nnot even start certain operations if the request has already finished.\n\n### Example\n\nThe following code ensures that file descriptors are always closed\nonce the response finishes.\n\n```js\nvar destroy = require('destroy')\nvar http = require('http')\nvar onFinished = require('finished')\n\nhttp.createServer(function onRequest(req, res) {\n  var stream = fs.createReadStream('package.json')\n  stream.pipe(res)\n  onFinished(res, function (err) {\n    destroy(stream)\n  })\n})\n```\n\n## License\n\n[MIT](LICENSE)\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/jshttp/on-finished/issues"
  },
  "homepage": "https://github.com/jshttp/on-finished",
  "_id": "on-finished@2.1.0",
  "_shasum": "0c539f09291e8ffadde0c8a25850fb2cedc7022d",
  "_from": "on-finished@2.1.0",
  "_resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.1.0.tgz"
}
