"> " />
欢迎来到天天文库
浏览记录
ID:15720968
大小:29.00 KB
页数:3页
时间:2018-08-05
《gzip、deflate压缩算法对应的c#压缩解压函数》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、GZip、Deflate压缩算法对应的C#压缩解压函数 /// ///GZip解压函数 /// /// /// publicbyte[]GZipDecompress(byte[]data) { using(MemoryStreamstream=newMemoryStream()) { using(GZipSt
2、reamgZipStream=newGZipStream(newMemoryStream(data),CompressionMode.Decompress)) { byte[]bytes=newbyte[40960]; intn; while((n=gZipStream.Read(bytes,0,bytes.Length))!=0) { stream.Write
3、(bytes,0,n); } gZipStream.Close(); } returnstream.ToArray(); } } /// ///GZip压缩函数 /// /// /// publicbyte[]GZipC
4、ompress(byte[]data) { using(MemoryStreamstream=newMemoryStream()) { using(GZipStreamgZipStream=newGZipStream(stream,CompressionMode.Compress)) { gZipStream.Write(data,0,data.Length); gZipStream.Close(
5、); } returnstream.ToArray(); } } /// ///Deflate解压函数 ///JS:vardetails=eval('('+utf8to16(zip_depress(base64decode(hidEnCode.value)))+')')对应的C#压缩方法 /// /// ///6、urns> publicstringDeflateDecompress(stringstrSource) { byte[]buffer=Convert.FromBase64String(strSource); using(System.IO.MemoryStreamms=newSystem.IO.MemoryStream()) { ms.Write(buffer,0,buffer.Length); ms.Positi7、on=0; using(System.IO.Compression.DeflateStreamstream=newSystem.IO.Compression.DeflateStream(ms,System.IO.Compression.CompressionMode.Decompress)) { stream.Flush(); intnSize=16*1024+256; //假设字符串
6、urns> publicstringDeflateDecompress(stringstrSource) { byte[]buffer=Convert.FromBase64String(strSource); using(System.IO.MemoryStreamms=newSystem.IO.MemoryStream()) { ms.Write(buffer,0,buffer.Length); ms.Positi
7、on=0; using(System.IO.Compression.DeflateStreamstream=newSystem.IO.Compression.DeflateStream(ms,System.IO.Compression.CompressionMode.Decompress)) { stream.Flush(); intnSize=16*1024+256; //假设字符串
此文档下载收益归作者所有