基于pako.js达成gzip的压缩和解压效率示例_javascript技巧_脚本之家

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

本文实例讲述了js基于qrcode.js生成二维码的方法。分享给大家供大家参考,具体如下:

本文实例讲述了基于代数方程库Algebra.js解二元一次方程功能。分享给大家供大家参考,具体如下:

 pako.js实现gzip的压缩和解压var b64Data = 'H4sIAAAAAAAAAJ3UMQ7CMAwF0KugP2ewEzdpcxXUAbWAOiHUMqCqdyeVQAobfGXIYL8hP5ZXnEdkeNEk6vUgXTbLonC4zMjHFY/5Wm511ekdTsOCLKVp2rlIKOA2jTuBot/cr7BhobEwsbAloY8kDGyqoQ5H/oHsdwQ21cCmaspCz0L2jcYOgLHhNGw4TT1yVmBpuS9PZHWY35siqnxvimEvpE9FY4peQhfbhO0FDnuFqWAEAAA=';var ticketData = '{"ed":"20170121 09:44:01","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":"20161021 09:44:01","cd":"72016102116762039687"}';// Output to consolevar s = unzip;console.log;console.log;var data = zip;console.log;console.log;function unzip{ var strData = atob; // Convert binary string to character-number array var charData = strData.split{return x.charCodeAt; // Turn number array into byte-array var binData = new Uint8Array; // // unzip var data = pako.inflate; // Convert gunzipped byteArray back to ascii string: strData = String.fromCharCode.apply(null, new Uint16Array; return strData;}function zip{ var binaryString = pako.gzip(str, { to: 'string' }); return btoa;}

www.hj8828.com,调用qrcode.js文件代码:

假设二元一次方程如下:

poko.js可至Github下载:

    #qrcode{ /*text-align: center;*/ /*display: table-cell;*/ /*width: 96px;*/ /*height: 96px;*/ /*vertical-align:middle;*/ /*position: relative;*/ }  点击更换验证码 window.onload =function(){ var qrcode = new QRCode(document.getElementById, { width : 96,//设置宽高 height : 96 }); qrcode.makeCode; document.getElementById.onclick =function(){ qrcode.makeCode(document.getElementById; } }

var qrcode = new QRCode(elem, { width : 96,//设置宽高 height : 96});qrcode.makeCode;
x + y = 11x - y = 5

 测试algebra函数库   var Fraction = algebra.Fraction; var Expression = algebra.Expression; var Equation = algebra.Equation; //======================================= var x1 = algebra.parse; var answer1 = x1.solveFor; //console.log("y = " + answer1.toString; var x2 = algebra.parse; var answer2 = x2.solveFor; //console.log("y = " + answer2.toString; //================================================= //解出X值 var eq = new Equation; console.log("x表达式:" + eq.toString; var answerX = eq.solveFor; console.log("解出X的值为:" + answerX.toString; //================================================= //解出Y值 eq = x1.eval; console.log("y表达式:" + eq.toString; var answerY = eq.solveFor; console.log("解出Y的值为:" + answerY.toString; 

x表达式:-x + 11 = x - 5解出X的值为:8y表达式:y + 8 = 11解出Y的值为:3

或者点击此处本站下载

附:

代码写得很粗旷,无任何包装。看得懂就好。