'use strict';constPassThrough=require('stream').PassThrough;constzlib=require('zlib');constmimicResponse=require('mimic-response');module.exports=response=>{// TODO: Use Array#includes when targeting Node.js 6if(['gzip','deflate'].indexOf(response.headers['content-encoding'])===-1){returnresponse;}constunzip=zlib.createUnzip();conststream=newPassThrough();mimicResponse(response,stream);unzip.on('error',err=>{if(err.code==='Z_BUF_ERROR'){stream.end();return;}stream.emit('error',err);});response.pipe(unzip).pipe(stream);returnstream;};