Unity BZip2压缩和解压,基于C#

  1. 基于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));

posted @ 2012-05-08 09:31  peiandsky  阅读(1675)  评论(0编辑  收藏  举报