using UnityEngine;using System.Collections;using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.GZip;using System.IO;
using System.Text;
using System;
public class RecodeAndSave:MonoBehaviour {
void Start() {
byte[] binary = Encoding.UTF8.GetBytes("你好,我是小小酥.很高兴为您服务");
Debug.Log("原始数据是"+Encoding.UTF8.GetString(binary));
byte[] press = Compress(binary);
Debug.Log("压缩后的数据是"+Convert.ToBase64String(press)+"长度是"+press.Length);
byte[] depress = DeCompress(press);
Debug.Log("解压后的数据是"+Encoding.UTF8.GetString(depress));
}
byte[] Compress(byte[] binary) {
MemoryStream ms = new MemoryStream();
GZipOutputStream gzip = new GZipOutputStream(ms);
gzip.Write(binary,0,binary.Length);
gzip.Close();
byte[] press = ms.ToArray();
return press;
}
byte[] DeCompress(byte[] press) {
GZipInputStream gzi = new GZipInputStream(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();
return depress;
}}
Unity3D使用压缩和解压算法的代码
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- zlib介绍 zlib是提供数据压缩用的函式库,由Jean-loup Gailly与Mark Adler所开发,初...