socketioMEANseed/www/node_modules/union/examples/simple/middleware/gzip-decode.js
www/node_modules/union/examples/simple/middleware/gzip-decode.jsRaw
1var spawn = require('child_process').spawn,
2 util = require('util'),
3 RequestStream = require('../../lib').RequestStream;
4
5var GzipDecode = module.exports = function GzipDecoder(options) {
6 RequestStream.call(this, options);
7
8 this.on('pipe', this.decode);
9}
10
11util.inherits(GzipDecode, RequestStream);
12
13GzipDecode.prototype.decode = function (source) {
14 this.decoder = spawn('gunzip');
15 this.decoder.stdout.on('data', this._onGunzipData.bind(this));
16 this.decoder.stdout.on('end', this._onGunzipEnd.bind(this));
17 source.pipe(this.decoder);
18}
19
20GzipDecoderStack.prototype._onGunzipData = function (chunk) {
21 this.emit('data', chunk);
22}
23
24GzipDecoderStack.prototype._onGunzipEnd = function () {
25 this.emit('end');
26}