- 基于BZip2的压缩方式(ICSharpCode.SharpZipLib)
压缩和解压代码举例:
MemoryStream ms = new MemoryStream();
BZip2OutputStream zlib = new BZip2OutputStream(ms);
byte[] src = Encoding.UTF8.GetBytes("#¥%……%……&@");
zlib.Write(src, 0, src.Length);
zlib.Close();
byte[] press = ms.ToArray();
Debug.Log(Convert.ToBase64String(press) + " " + press.Length);
BZip2InputStream gzi = new BZip2InputStream(new MemoryStream(press));
MemoryStream re = new MemoryStream();
int count = 0;
byte[] data = new byte[4096];
while ((count = gzi.Read(data, 0, data.Length)) != 0)
{
re.Write(data, 0, count);
}
byte[] depress = re.ToArray();
Debug.Log(Encoding.UTF8.GetString(depress));