关于压缩MemoryStream和解压缩Memory的方法!

lcg200x 2005-03-11 12:28:58
我从网上来的总包错
private void c1CommandHolder1_CommandClick(object sender, C1.Win.C1Command.CommandClickEventArgs e)
{
Microsoft.DataAccess.ConnectionManager.AddConnection("Default","user id=dev;password=do4best;initial catalog=Northwind;data source=192.168.32.175;Connect Timeout=1000");
DataSet tmpds = SqlHelper.ExecuteDataset("Default",CommandType.Text,"Select * from Customers",null);
Stream ms = new MemoryStream();
tmpds.WriteXml(ms,System.Data.XmlWriteMode.WriteSchema);

// System.Text.Encoding.Default.GetBytes(
//
Stream mms = ZipStream(ms);
int a = (int)mms.Length;
// byte[] msbyte = new byte[(int)mms.Length];
// ms.Write(msbyte,0,(int)mms.Length);
// MemoryStream mmms = new MemoryStream(msbyte,0,msbyte.Length);
ms = UnZipStream(mms);
a = (int)ms.Length;


}

public Stream UnZipStream(Stream zipedStream)
{
DeflaterOutputStream outStream = new DeflaterOutputStream(new MemoryStream());
zipedStream.Seek(0,SeekOrigin.Begin);
ZipInputStream s=new ZipInputStream(zipedStream);
ZipEntry theEntry;
if ((theEntry = s.GetNextEntry()) != null) //这里报错说未处理的“ICSharpCode.SharpZipLib.ZipException”类型的异常出现在 sharpziplib.dll 中。

其他信息: Wrong Local header signature-1041392520

{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
outStream.Write(data, 0, size);
}
else
{
break;
}
}
}
return outStream;
}


public Stream ZipStream(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes,0,bytes.Length);
DeflaterOutputStream s = new DeflaterOutputStream(new MemoryStream());
s.Write(bytes,0,bytes.Length);
s.Finish();
return s;
}
救救我啊 谢谢!解决这个问题的人 这个帖子得分也归他
http://community.csdn.net/Expert/topic/3837/3837274.xml?temp=.6056177
这个帖子我已经解决了 解决压缩问题的人 能领到 这个帖子得分 一共150
...全文
317 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
corbet 2005-03-22
  • 打赏
  • 举报
回复
帮你顶上去!
coolksj 2005-03-21
  • 打赏
  • 举报
回复
压缩Stream很常见,你使用的方法我没用过.

.Net中提供一个压缩类,和你的方法非常类似.但他是使用Java中的压缩类实现的.

那个类我用过,没有问题,完全可以实现压缩和解压
fds2003 2005-03-21
  • 打赏
  • 举报
回复
up
hwp82 2005-03-21
  • 打赏
  • 举报
回复
up
godhand2 2005-03-18
  • 打赏
  • 举报
回复
qpcegg 2005-03-17
  • 打赏
  • 举报
回复
up
aiur2000 2005-03-17
  • 打赏
  • 举报
回复
帮顶!
zr1982930 2005-03-15
  • 打赏
  • 举报
回复
帮顶!
cutman 2005-03-11
  • 打赏
  • 举报
回复
帮你up
lcg200x 2005-03-11
  • 打赏
  • 举报
回复
自己顶!

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧