How to decompress Gzip Json response via Axios

冷暖自知 提交于 2021-01-23 11:11:31

问题


I am using Axios to get the JSON response from the web server. The response is in compressed gzip format. How can I decompress the response and get the Json Data.


回答1:


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())
  })


来源:https://stackoverflow.com/questions/62882796/how-to-decompress-gzip-json-response-via-axios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!