首先引入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())
评论
发表评论