package.json 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {
  2. "name": "on-finished",
  3. "description": "Execute a callback when a request closes, finishes, or errors",
  4. "version": "2.2.0",
  5. "contributors": [
  6. {
  7. "name": "Douglas Christopher Wilson",
  8. "email": "doug@somethingdoug.com"
  9. },
  10. {
  11. "name": "Jonathan Ong",
  12. "email": "me@jongleberry.com",
  13. "url": "http://jongleberry.com"
  14. }
  15. ],
  16. "license": "MIT",
  17. "repository": {
  18. "type": "git",
  19. "url": "git://github.com/jshttp/on-finished"
  20. },
  21. "dependencies": {
  22. "ee-first": "1.1.0"
  23. },
  24. "devDependencies": {
  25. "istanbul": "0.3.5",
  26. "mocha": "~2.0.1"
  27. },
  28. "engines": {
  29. "node": ">= 0.8"
  30. },
  31. "files": [
  32. "HISTORY.md",
  33. "LICENSE",
  34. "index.js"
  35. ],
  36. "scripts": {
  37. "test": "mocha --reporter spec --bail --check-leaks test/",
  38. "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
  39. "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
  40. },
  41. "readme": "# on-finished\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\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. If the response\nhas already finished, the listener will be invoked.\n\nListening to the end of a response would be used to close things associated\nwith the response, like open files.\n\nListener is invoked as `listener(err, res)`.\n\n```js\nonFinished(res, function (err, res) {\n // clean up open fds, etc.\n // err contains the error is request error'd\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. If the request\nhas already finished, the listener will be invoked.\n\nListening to the end of a request would be used to know when to continue\nafter reading the data.\n\nListener is invoked as `listener(err, req)`.\n\n```js\nvar data = ''\n\nreq.setEncoding('utf8')\nres.on('data', function (str) {\n data += str\n})\n\nonFinished(req, function (err, req) {\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('on-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\n[npm-image]: https://img.shields.io/npm/v/on-finished.svg?style=flat\n[npm-url]: https://npmjs.org/package/on-finished\n[node-version-image]: https://img.shields.io/node/v/on-finished.svg?style=flat\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/jshttp/on-finished.svg?style=flat\n[travis-url]: https://travis-ci.org/jshttp/on-finished\n[coveralls-image]: https://img.shields.io/coveralls/jshttp/on-finished.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/jshttp/on-finished?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/on-finished.svg?style=flat\n[downloads-url]: https://npmjs.org/package/on-finished\n",
  42. "readmeFilename": "README.md",
  43. "bugs": {
  44. "url": "https://github.com/jshttp/on-finished/issues"
  45. },
  46. "homepage": "https://github.com/jshttp/on-finished",
  47. "_id": "on-finished@2.2.0",
  48. "_shasum": "e6ba6a09a3482d6b7969bc3da92c86f0a967605e",
  49. "_from": "on-finished@~2.2.0",
  50. "_resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.2.0.tgz"
  51. }