{
  "name": "raw-body",
  "description": "Get and validate the raw body of a readable stream.",
  "version": "2.1.4",
  "author": {
    "name": "Jonathan Ong",
    "email": "me@jongleberry.com",
    "url": "http://jongleberry.com"
  },
  "contributors": [
    {
      "name": "Douglas Christopher Wilson",
      "email": "doug@somethingdoug.com"
    },
    {
      "name": "Raynos",
      "email": "raynos2@gmail.com"
    }
  ],
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git://github.com/stream-utils/raw-body"
  },
  "dependencies": {
    "bytes": "2.1.0",
    "iconv-lite": "0.4.12",
    "unpipe": "1.0.0"
  },
  "devDependencies": {
    "bluebird": "2.10.1",
    "istanbul": "0.3.21",
    "mocha": "2.2.5",
    "readable-stream": "2.0.2",
    "through2": "2.0.0"
  },
  "engines": {
    "node": ">= 0.8"
  },
  "files": [
    "HISTORY.md",
    "LICENSE",
    "README.md",
    "index.js"
  ],
  "scripts": {
    "test": "mocha --trace-deprecation --reporter spec --bail --check-leaks test/",
    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --trace-deprecation --reporter dot --check-leaks test/",
    "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --trace-deprecation --reporter spec --check-leaks test/"
  },
  "readme": "# raw-body\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\nGets the entire buffer of a stream either as a `Buffer` or a string.\nValidates the stream's length against an expected length and maximum limit.\nIdeal for parsing request bodies.\n\n## API\n\n```js\nvar getRawBody = require('raw-body')\n```\n\n### getRawBody(stream, [options], [callback])\n\n**Returns a promise if no callback specified and global `Promise` exists.**\n\nOptions:\n\n- `length` - The length length of the stream.\n  If the contents of the stream do not add up to this length,\n  an `400` error code is returned.\n- `limit` - The byte limit of the body.\n  If the body ends up being larger than this limit,\n  a `413` error code is returned.\n- `encoding` - The requested encoding.\n  By default, a `Buffer` instance will be returned.\n  Most likely, you want `utf8`.\n  You can use any type of encoding supported by [iconv-lite](https://www.npmjs.org/package/iconv-lite#readme).\n\nYou can also pass a string in place of options to just specify the encoding.\n\n`callback(err, res)`:\n\n- `err` - the following attributes will be defined if applicable:\n\n    - `limit` - the limit in bytes\n    - `length` and `expected` - the expected length of the stream\n    - `received` - the received bytes\n    - `encoding` - the invalid encoding\n    - `status` and `statusCode` - the corresponding status code for the error\n    - `type` - either `entity.too.large`, `request.aborted`, `request.size.invalid`, `stream.encoding.set`, or `encoding.unsupported`\n\n- `res` - the result, either as a `String` if an encoding was set or a `Buffer` otherwise.\n\nIf an error occurs, the stream will be paused, everything unpiped,\nand you are responsible for correctly disposing the stream.\nFor HTTP requests, no handling is required if you send a response.\nFor streams that use file descriptors, you should `stream.destroy()` or `stream.close()` to prevent leaks.\n\n## Examples\n\n### Simple Express example\n\n```js\nvar getRawBody = require('raw-body')\nvar typer = require('media-typer')\n\napp.use(function (req, res, next) {\n  getRawBody(req, {\n    length: req.headers['content-length'],\n    limit: '1mb',\n    encoding: typer.parse(req.headers['content-type']).parameters.charset\n  }, function (err, string) {\n    if (err) return next(err)\n    req.text = string\n    next()\n  })\n})\n```\n\n### Simple Koa example\n\n```js\napp.use(function* (next) {\n  var string = yield getRawBody(this.req, {\n    length: this.length,\n    limit: '1mb',\n    encoding: this.charset\n  })\n})\n```\n\n### Using as a promise\n\nTo use this library as a promise, simply omit the `callback` and a promise is\nreturned, provided that a global `Promise` is defined.\n\n```js\nvar getRawBody = require('raw-body')\nvar http = require('http')\n\nvar server = http.createServer(function (req, res) {\n  getRawBody(req)\n  .then(function (buf) {\n    res.statusCode = 200\n    res.end(buf.length + ' bytes submitted')\n  })\n  .catch(function (err) {\n    res.statusCode = 500\n    res.end(err.message)\n  })\n})\n\nserver.listen(3000)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/raw-body.svg\n[npm-url]: https://npmjs.org/package/raw-body\n[node-version-image]: https://img.shields.io/node/v/raw-body.svg\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/stream-utils/raw-body/master.svg\n[travis-url]: https://travis-ci.org/stream-utils/raw-body\n[coveralls-image]: https://img.shields.io/coveralls/stream-utils/raw-body/master.svg\n[coveralls-url]: https://coveralls.io/r/stream-utils/raw-body?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/raw-body.svg\n[downloads-url]: https://npmjs.org/package/raw-body\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/stream-utils/raw-body/issues"
  },
  "homepage": "https://github.com/stream-utils/raw-body",
  "_id": "raw-body@2.1.4",
  "dist": {
    "shasum": "fa2447c989a585c2b8b2ed70950369b6bd572c98"
  },
  "_from": "raw-body@~2.1.2",
  "_resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.1.4.tgz"
}
