js 使用pako压缩json字符串

官网: http://nodeca.github.io/pako/
代码如下:(参考:http://www.qiutianaimeili.com/html/_page/2019/12/source/pako/example.html,扒的代码,简单粗暴)

  //解压缩
  unzipFun(b64Data) {
      console.log(b64Data)
      var data = "";
      try {
        var strData = atob(b64Data);
        data = window.pako.inflate(strData, {
          to: "string",
        });

          console.log(data);
          console.log(JSON.parse(data));
          return JSON.parse(data);
      } catch (ex) {
        console.log("报错了:" + ex);
        return false
      }

    },
    // 压缩
    zipFun(str, name) {
      var binaryString = window.pako.deflate(str, {
        to: "string",
        level: 9,
      });
      console.log(btoa(binaryString));
      return  btoa(binaryString)
    },
  • js 版本
    参考:https://blog.csdn.net/qq_43474419/article/details/126730439

你可能感兴趣的:(js 使用pako压缩json字符串)