{
  "name": "raw-body",
  "description": "Get and validate the raw body of a readable stream.",
  "version": "1.3.0",
  "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": "1",
    "iconv-lite": "0.4.4"
  },
  "devDependencies": {
    "istanbul": "0.3.0",
    "mocha": "~1.20.1",
    "readable-stream": "~1.0.17",
    "through2": "~0.5.1"
  },
  "engines": {
    "node": ">= 0.8.0"
  },
  "scripts": {
    "test": "mocha --reporter spec --bail 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": "# raw-body\n\n[![NPM version](https://badge.fury.io/js/raw-body.svg)](http://badge.fury.io/js/raw-body)\n[![Build Status](https://travis-ci.org/stream-utils/raw-body.svg?branch=master)](https://travis-ci.org/stream-utils/raw-body)\n[![Coverage Status](https://img.shields.io/coveralls/stream-utils/raw-body.svg?branch=master)](https://coveralls.io/r/stream-utils/raw-body)\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')\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)\n      return next(err)\n\n    req.text = string\n    next()\n  })\n})\n```\n\nor in a Koa generator:\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### getRawBody(stream, [options], [callback])\n\nReturns a thunk for yielding with generators.\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.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## 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/stream-utils/raw-body/issues"
  },
  "homepage": "https://github.com/stream-utils/raw-body",
  "_id": "raw-body@1.3.0",
  "_shasum": "978230a156a5548f42eef14de22d0f4f610083d1",
  "_from": "raw-body@1.3.0",
  "_resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.3.0.tgz"
}
