iching-broker-level2/node_modules/union/examples/simple/middleware/gzip-decode.js
Christopher Hase b27a419c2f
All checks were successful
ci / build (push) Successful in 1m33s
add http-server part 5
2025-04-09 11:10:36 +02:00

26 lines
No EOL
725 B
JavaScript

var spawn = require('child_process').spawn,
util = require('util'),
RequestStream = require('../../lib').RequestStream;
var GzipDecode = module.exports = function GzipDecoder(options) {
RequestStream.call(this, options);
this.on('pipe', this.decode);
}
util.inherits(GzipDecode, RequestStream);
GzipDecode.prototype.decode = function (source) {
this.decoder = spawn('gunzip');
this.decoder.stdout.on('data', this._onGunzipData.bind(this));
this.decoder.stdout.on('end', this._onGunzipEnd.bind(this));
source.pipe(this.decoder);
}
GzipDecoderStack.prototype._onGunzipData = function (chunk) {
this.emit('data', chunk);
}
GzipDecoderStack.prototype._onGunzipEnd = function () {
this.emit('end');
}