您好,欢迎访问一九零五行业门户网

js实现gzip解压缩的代码实现

本篇文章给大家带来的内容是关于js实现gzip解压缩的代码实现,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
代码如下:
<!doctype html><html lang="zh"><head> <meta charset="utf-8"> <title>document</title> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/pako/1.0.6/pako.min.js"></script> </head> <body> <input id="content" type="text"> <button onclick="encode()">encode</button> <button onclick="decode()">decode</button> <div id="ciphertext"></div> </body> </html> <script type="text/javascript"> function encode(){ var str = $('#content').val(); str = window.btoa(pako.gzip(str, {to: "string"})) $('#ciphertext').text(str);}function decode(){ var encodeddata = $('#content').val(); var decodeddata = window.atob(encodeddata); var chardata = decodeddata.split('').map(function(x){return x.charcodeat(0);}); var bindata = new uint8array(chardata); var data = pako.inflate(bindata); decodeddata = string.fromcharcode.apply(null, new uint16array(data)); $('#ciphertext').text(decodeddata);}</script>
相关推荐:
vue.js组件中全局注册和局部注册的简单介绍以及实例分析
js如何来实现获取滚动条宽度(代码示例
以上就是js实现gzip解压缩的代码实现的详细内容。
其它类似信息

推荐信息