1.服务器保存的数据是zlib压缩过的,客户端用DeflateStream解压
2.System.IO.Compression 在android上不支持 需要下载Unity.IO.Compression放入工程
下载地址:https://github.com/Hitcents/Unity.IO.Compression
目录:
3.解压代码
using Unity.IO.Compression;
需要跳过zlib的头部2位:offset传2(其他压缩格式未验证) lenght数组长度
public static byte[] UnZipData(byte[] byteArray,int offset,int lenght)
{
var ms = new MemoryStream(byteArray) { Position = offset };
var outms = new MemoryStream();
using (var deflateStream = new DeflateStream(ms, CompressionMode.Decompress, true))
{
var buf = new byte[lenght];
int len;
while ((len = deflateStream.Read(buf, 0, buf.Length)) > 0)
outms.Write(buf, 0, len);
}
return outms.ToArray();
}
网友评论