如何通过Axios解压缩Gzip Json响应

如何通过Axios解压缩Gzip Json响应,json,axios,compression,gzip,response,Json,Axios,Compression,Gzip,Response,我使用Axios从web服务器获取JSON响应。响应是压缩的gzip格式。如何解压缩响应并获取Json数据 const zlib = require('zlib') let url = "https://example.com/GZ_FILE.gz" const { data } = await axios.get(url, { responseType: 'arraybuffer' }) zlib.gunzip(data, function (_err, output

我使用Axios从web服务器获取JSON响应。响应是压缩的gzip格式。如何解压缩响应并获取Json数据

const zlib = require('zlib')

let url = "https://example.com/GZ_FILE.gz"

const { data } = await axios.get(url, { responseType: 'arraybuffer' })

zlib.gunzip(data, function (_err, output) {
    console.log(output.toString())
  })