<script src="https://cdn.bootcss.com/pako/1.0.6/pako.min.js"></script> 或者 npm install pako
1 function unzip(b64Data){
2 var strData = atob(b64Data);
3 // Convert binary string to character-number array
4 var charData = strData.split('').map(function(x){return x.charCodeAt(0);});
5 // Turn number array into byte-array
6 var binData = new Uint8Array(charData);
7 // // unzip
8 var data = pako.inflate(binData);
9 // Convert gunzipped byteArray back to ascii string:
10 strData = String.fromCharCode.apply(null, new Uint16Array(data));
11 return decodeURIComponent(strData);
12 }
13 function zip(str){
14 var binaryString = pako.gzip(encodeURIComponent(str), { to: 'string' })
15 return btoa(binaryString);
16 }