Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

raw-body

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raw-body - npm Package Compare versions

Comparing version 1.1.7 to 1.2.0

6

HISTORY.md

@@ -0,1 +1,7 @@

1.2.0 / 2014-06-13
==================
* Passing string as `options` interpreted as encoding
* Support all encodings from `iconv-lite`
1.1.7 / 2014-06-12

@@ -2,0 +8,0 @@ ==================

44

index.js
var bytes = require('bytes')
var iconv = require('iconv-lite')
// NOTE: the trailing slash is not a typo
var StringDecoder = require('string_decoder/').StringDecoder
module.exports = function (stream, options, done) {
if (options === true || typeof options === 'string') {
// short cut for encoding
options = {
encoding: options
}
}
module.exports = function (stream, options, done) {
options = options || {}
if (typeof options === 'function') {
done = options
options = {}
} else if (!options) {
options = {}
} else if (options === true) {
options = {
encoding: 'utf8'
}
}
// get encoding
var encoding = options.encoding !== true
? options.encoding
: 'utf-8'
// convert the limit to an integer

@@ -68,6 +74,3 @@ var limit = null

var received = 0
// note: we delegate any invalid encodings to the constructor
var decoder = options.encoding
? new StringDecoder(options.encoding === true ? 'utf8' : options.encoding)
: null
var decoder = getDecoder(encoding)
var buffer = decoder

@@ -121,3 +124,3 @@ ? ''

done(null, decoder
? buffer + decoder.end()
? buffer + (decoder.end() || '')
: Buffer.concat(buffer)

@@ -140,2 +143,15 @@ )

function getDecoder(encoding) {
if (!encoding) return null
try {
return iconv.getCodec(encoding).decoder()
} catch (e) {
var err = makeError('specified encoding unsupported', 'encoding.unsupported')
err.status = err.statusCode = 415
err.encoding = encoding
throw err
}
}
// to create serializable errors you must re-set message so

@@ -142,0 +158,0 @@ // that it is enumerable and you must re configure the type

{
"name": "raw-body",
"description": "Get and validate the raw body of a readable stream.",
"version": "1.1.7",
"version": "1.2.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -10,3 +10,3 @@ "license": "MIT",

"bytes": "1",
"string_decoder": "0.10"
"iconv-lite": "0.4.2"
},

@@ -13,0 +13,0 @@ "devDependencies": {

# raw-body
[![NPM version](https://badge.fury.io/js/method-override.svg)](http://badge.fury.io/js/raw-body)
[![NPM version](https://badge.fury.io/js/raw-body.svg)](http://badge.fury.io/js/raw-body)
[![Build Status](https://travis-ci.org/stream-utils/raw-body.svg?branch=master)](https://travis-ci.org/stream-utils/raw-body)

@@ -15,2 +15,3 @@ [![Coverage Status](https://img.shields.io/coveralls/stream-utils/raw-body.svg?branch=master)](https://coveralls.io/r/stream-utils/raw-body)

var getRawBody = require('raw-body')
var typer = require('media-typer')

@@ -21,3 +22,3 @@ app.use(function (req, res, next) {

limit: '1mb',
encoding: 'utf8'
encoding: typer.parse(req.headers['content-type']).parameters.charset
}, function (err, string) {

@@ -40,3 +41,3 @@ if (err)

limit: '1mb',
encoding: 'utf8'
encoding: this.charset
})

@@ -61,5 +62,6 @@ })

Most likely, you want `utf8`.
You can use any type of encoding supported by [StringDecoder](http://nodejs.org/api/string_decoder.html).
You can also pass `true` which sets it to the default `utf8`
You can use any type of encoding supported by [iconv-lite](https://www.npmjs.org/package/iconv-lite#readme).
You can also pass a string in place of options to just specify the encoding.
`callback(err, res)`:

@@ -66,0 +68,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc