跳至主要内容

js利用pako.js


    首先引入js
<script src="pako.min.js"></script>

前端加上俩函数
    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   = new TextDecoder("utf-8").decode(data);
        alert(strData)
        return strData;
    }
    function zip(str){
         var binaryString = pako.gzip(encodeURIComponent(str), { to: 'string' })
         return btoa(binaryString);
    }

服务端先用 gzip然后base64
实际效果基本能节省一半
   var b bytes.Buffer   w := gzip.NewWriter(&b)
   defer w.Close()

   w.Write([]byte(data))
   w.Flush()

   data = base64.StdEncoding.EncodeToString(b.Bytes())

评论

此博客中的热门博文

ubuntu 添加root登录

Login to your server as root. As the root user, edit the sshd_config file found in  /etc/ssh/sshd_config : vim /etc/ssh/sshd_config ( For details on working with Vim check out our article here !) Add the following line to the file, you can add it anywhere but it’s good practice to find the block about authentication and add it there. PermitRootLogin yes Save and exit the file. Restart the SSH server: systemctl restart sshd or service sshd restart