Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I uncompress a gzip file in javascript?

I have gotten an ArrayBuffer data (called s as follows which consist of many blocks) from our serve side,the blob is generated as follows:

var blob=new Blob([s.slice(4,82838)]);

but the blob I have made is a gzip data;How can I uncompress it in javascript? I have tried zip.js but it didn't work?(and I still puzzled why it doesn't work). please tell me a method to un-compress the blob,thank you. (my English is poor,sorry)

like image 303
feixiangsnail Avatar asked Feb 07 '23 11:02

feixiangsnail


1 Answers

In the browser I have used pako

You may do something like..

var reader = new FileReader();
reader.onload = function(event) {
    var result = pako.inflate(event.target.result, { to: 'string' });
    console.log(result);
}
reader.readAsArrayBuffer(file));

If your environment is nodejs you have zlib capabilities

like image 64
Carlo Avatar answered Feb 11 '23 00:02

Carlo