zip.js 实现前端解压 zip字符串

时间:2023-05-09 17:21:04 买帖  | 投诉/举报

篇首语:本文由小编为大家整理,主要介绍了zip.js 实现前端解压 zip字符串相关的知识,希望对你有一定的参考价值。

项目需求

H5 App要求离线更新数据(不会有接口提供).由于数据不是很大.考虑用类似注册码的方式.获得一串json数据体后按用户对称加密再zip压缩转base64分发. 由用户手动复制字符串黏贴到应用输入框中进行更新.

简要实现方式

由java端进行 json数据体的 加密->zip->base64由页面端进行解密

页面端解密方式

使用 zipJS

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1.0">  <meta http-equiv="X-UA-Compatible" content="ie=edge">  <script type="text/javascript" src="zip.js"></script>  <title>Document</title></head><body><script>var zz='zip后的的base64字符串  ==';  // 要替换这里//解压base64 zip字符流function unzipString(base64,cb)  zip.createReader(new zip.Data64URIReader(base64), function(reader)   reader.getEntries(function(entries)     if (entries.length)       entries[0].getData(new zip.TextWriter(), function(text)         cb(text);        reader.close(function()         );      , function(current, total)       );      );  , function(error)   );String.prototype.replaceAll  = function(s1,s2)    return this.replace(new RegExp(s1,"gm"),s2);unzipString(zz,function(retVal)  console.log(retVal.toString()););</script></body></html>

以上是关于zip.js 实现前端解压 zip字符串的主要内容,如果未能解决你的问题,请参考以下文章