index.js 637 B

12345678910111213141516171819202122232425262728293031323334
  1. var zlib = require('zlib')
  2. module.exports = inflate
  3. function inflate(stream, options) {
  4. if (!stream) {
  5. throw new TypeError('argument stream is required')
  6. }
  7. options = options || {}
  8. var encoding = options.encoding
  9. || (stream.headers && stream.headers['content-encoding'])
  10. || 'identity'
  11. switch (encoding) {
  12. case 'gzip':
  13. case 'deflate':
  14. break
  15. case 'identity':
  16. return stream
  17. default:
  18. var err = new Error('Unsupported Content-Encoding: ' + encoding)
  19. err.status = 415
  20. throw err
  21. }
  22. // no not pass-through encoding
  23. delete options.encoding
  24. return stream.pipe(zlib.Unzip(options))
  25. }