1.0.2 • Published 8 years ago

body-parser-zlib v1.0.2

Weekly downloads
6
License
GPL 3
Repository
github
Last release
8 years ago

gzip Body Parser

Adds zlib as parser to the body-parser library, so you can convert incoming gziped data into a string representation.

This is really useful if you want to read gziped requests to save size

Build Status npm version Dependency Status devDependency Status

Installation

npm install --save express body-parser body-parser-zlib

Usage

This library adds an zlib method to the body-parser object.

Initialise like so:

var bodyParser = require('body-parser');
require('body-parser-zlib')(bodyParser);

Once initialised, you can use it just like any other body-parser middleware:

var app = require('express')();
app.use(bodyParser.zlib());

This will parse any gziped request and place it as a JavaScript object on req.body for your route handlers to use.

Example

var express = require('express'),
    bodyParser = require('body-parser');

require('body-parser-zlib')(bodyParser);

var app = express();
app.use(bodyParser.zlib());

app.post('/users', function(req, res, body) {
  // Any request with an Zlib payload will be parsed
  // and a String produced on req.body
  // corresponding to the request payload.
  console.log(req.body);
  res.status(200).end();
});

For Single routes

var express = require('express'),
    bodyParser = require('body-parser');
var zlibParser;


var app = express();
require('body-parser-zlib')(bodyParser);
var zlibParser = bodyParser.zlib();

app.post('/users', zlib, function(req, res, body) {
  // Any request with an Zlib payload will be parsed
  // and a String produced on req.body
  // corresponding to the request payload.
  console.log(req.body);
  res.status(200).end();
});

Motivation

This library was born out of a frustration that body-parser, doesn't support parsing gziped content, if the header was not set, so for old systems you can use this

License

GPL 3