日期:2014-05-18 浏览次数:21295 次
public static string DecompressGZip(string unCompressedString) { System.Text.StringBuilder uncompressedString = new System.Text.StringBuilder(); byte[] writeData = new byte[4096]; //将string字符串解码(转换为等效的8位无符号整数数组) byte[] bytData = System.Convert.FromBase64String(sunCompressedString); int totalLength = 0; int size = 0; //解压缩基础流来创建zip流对象 Stream s = new GZipStream(new MemoryStream(bytData), CompressionMode.Decompress); using (var ms = new MemoryStream()) { var len = 0; while ((len = s.Read(writeData, 0, writeData.Length)) > 0) { ms.Write(writeData, 0, len); } uncompressedString.Append(Encoding.UTF8.GetString(ms.ToArray())); } s.Close();//关闭流 return uncompressedString.ToString();//返回字符串 }
------解决方案--------------------
4楼代码这个位置打错了,多了个 s
byte[] bytData = System.Convert.FromBase64String(unCompressedString);
------解决方案--------------------
using (var ms = new MemoryStream())
改成
using (MemoryStream ms = new MemoryStream())
------解决方案--------------------
var len = 0;
该成
int len = 0;