小程序界面设计模板_基于pako.js完成gzip的压缩宽

摘要: 根据pako.js完成gzip的缩小调解压作用实例 本文关键详细介绍了根据pako.js完成gzip的缩小调解压作用,融合实际案例方式剖析了pako.js完成标识符串缩小与缓解压力缩的有关实际操作方...

基于pako.js实现gzip的压缩和解压功能示例       这篇文章主要介绍了基于pako.js实现gzip的压缩和解压功能,结合具体实例形式分析了pako.js实现字符串压缩与解压缩的相关操作技巧,需要的朋友可以参考下

本文实例讲述了基于pako.js实现gzip的压缩和解压功能。分享给大家供大家参考,具体如下:

 !DOCTYPE html 
 html lang="en" 
 head 
 meta charset="UTF-8" 
 title pako.js实现gzip的压缩和解压 /title 
 /head 
 body 
 script type="text/javascript" src="pako.js" /script 
 script 
var b64Data = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/Cz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA=';
var ticketData = '{"ed":" ","fs":[{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"003","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"005","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"004","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"007","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"008","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"026","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"033","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"034","oids":["0"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"035","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"037","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"038","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"041","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"042","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"047","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"046","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"048","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"051","oids":["1"]},{"usg":[1,1,1,1,1,1,1],"act":0,"fid":"053","oids":["4"]}],"qty":1,"sd":" ","cd":""}';
// Output to console
var s = unzip(b64Data);
console.log("unzipped:");
console.log(s);
var data = zip(ticketData);
console.log("zipped:");
console.log(data);
function unzip(b64Data){
 var strData = atob(b64Data);
 // Convert binary string to character-number array
 var charData = strData.split('').map(function(x){return x.charCodeAt(0);});
 // Turn number array into byte-array
 var binData = new Uint8Array(charData);
 // // unzip
 var data = pako.inflate(binData);
 // Convert gunzipped byteArray back to ascii string:
 strData = String.fromCharCode.apply(null, new Uint16Array(data));
 return strData;
function zip(str){
 var binaryString = pako.gzip(str, { to: 'string' });
 return btoa(binaryString);
 /script 
 /body 
 /html 

运行效果图如下:

poko.js可至Github下载:nodeca/pako

或者点击此处。

更多关于JavaScript相关内容可查看本站专题:《》、《》、《》、《》、《》及《》

希望本文所述对大家JavaScript程序设计有所帮助。




联系我们

全国服务热线:4000-399-000 公司邮箱:343111187@qq.com

  工作日 9:00-18:00

关注我们

官网公众号

官网公众号

Copyright?2020 广州凡科互联网科技股份有限公司 版权所有 粤ICP备10235580号 客服热线 18720358503

技术支持:个人网页