The data returned by websocket is in gzip format. How to decompress it?

the data returned by websocket is in gzip format. How to decompress it?

function ws (url) {

var ws = new WebSocket(url);
ws.onopen = function(evt){
    console.log(evt);
};
ws.onmessage = function(evt){
    console.log(evt);                
};
ws.onerror = function(evt){
    console.log(evt);
}

}
ws ("wss://api.huobi.br.com/market/tickers");

the printed evt looks like this

clipboard.png

data is a Blob object.
looked up the information on the Internet and said that it can be decompressed by using the pako.inflate () method in pakojs, but I reported an error after using it:
Uncaught unknown compression method
/ / unknown compression method

so I don"t know how to decompress it.

Apr.16,2021

thanks to the idea from upstairs, the data I asked to return is a Blob object that stores binary data.
so you need to extract the data from the Blob object first, and then extract it with the pako.inflate () method

For more information about what a Blob object is, please see link description

.

the specific code is as follows:
ws.onmessage = function (evt) {

if(evt.data instanceof Blob){
    let result = '';
    let reader = new FileReader();
    //FileReader:Blob
    reader.onload = function() {
        result = JSON.parse(pako.inflate(reader.result,{to:'string'}));
       //pako.inflate()json
        if(result.ping){
            ws.send(JSON.stringify({pong:result.ping}));
            //
         }
     }
     reader.readAsBinaryString(evt.data);
     //
 }

};


this is not gzip, so there is no decompression.

can be used in this way


var reader = new FileReader();
reader.onload = function() {
    alert(reader.result);
}
reader.readAsText(evt);


Thank you, I also met

Menu