4

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)

feixiangsnail
  • 45
  • 1
  • 1
  • 6
  • Possible duplicate of [Fetching zipped text file and unzipping in client browers, feasible in Javascript?](http://stackoverflow.com/questions/14727856/fetching-zipped-text-file-and-unzipping-in-client-browers-feasible-in-javascrip) (The accepted answer provides a link that should be of interest to you.) – Arnauld Jul 28 '16 at 09:57

2 Answers2

8

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

Carlo
  • 2,103
  • 21
  • 29
0

In Nodejs, you can install unzip package.

npm install unzip

This is the document

RryLee
  • 535
  • 4
  • 6