You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
725 B

8 years ago
  1. var spawn = require('child_process').spawn,
  2. util = require('util'),
  3. RequestStream = require('../../lib').RequestStream;
  4. var GzipDecode = module.exports = function GzipDecoder(options) {
  5. RequestStream.call(this, options);
  6. this.on('pipe', this.decode);
  7. }
  8. util.inherits(GzipDecode, RequestStream);
  9. GzipDecode.prototype.decode = function (source) {
  10. this.decoder = spawn('gunzip');
  11. this.decoder.stdout.on('data', this._onGunzipData.bind(this));
  12. this.decoder.stdout.on('end', this._onGunzipEnd.bind(this));
  13. source.pipe(this.decoder);
  14. }
  15. GzipDecoderStack.prototype._onGunzipData = function (chunk) {
  16. this.emit('data', chunk);
  17. }
  18. GzipDecoderStack.prototype._onGunzipEnd = function () {
  19. this.emit('end');
  20. }