不知道从那里下载来的zlib 第三方库了.
我已经写好了zlib.d.ts 文件, 可直接拿来用.
链接: https://download.csdn.net/download/u013013797/11975180
压缩:
public zip(bytes: egret.ByteArray): Uint8Array {
let bufferArray: ArrayBuffer = new ArrayBuffer(bytes.length);
let plain: Uint8Array = new Uint8Array(bufferArray);
for (let i = 0; i < bytes.length; i++) {
plain[i] = bytes.bytes[i]
}
//zlib压缩
let deflate = new Zlib.Deflate(plain);
let compressed: Uint8Array = deflate.compress();
return compressed
}
解压缩:
public unzip(list: egret.ByteArray): egret.ByteArray {
//zlib解压缩
let inflate = new Zlib.Inflate(list.bytes);
let deplain: Uint8Array = inflate.decompress();
let bytes = new egret.ByteArray(deplain)
return bytes
}
发布到微信. 修改egret 工程中的 wxgame.ts 文件, 增加上下方代码:
if (filename == "libs/zlib/zlib.js" || filename == "libs/zlib/zlib.min.js") {
let len = content.lastIndexOf("this")
let str = content.substring(0, len)
content = str + "window);"
}