WP7上如何将数据用zip压缩和解压缩

sxfcct 2012-02-29 03:28:58
SharpZipLib中的zip压缩都是将文件进行压缩和解压缩(文件在压缩包中有一个entry),如何直接将内存中的数据进行zip压缩呢(不需要entry)?
...全文
781 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxf1976 2013-02-20
  • 打赏
  • 举报
回复
我不太懂。是否要在另外一个线程里做?
xzt2012 2013-02-18
  • 打赏
  • 举报
回复
楼主解决了吗?我现在也是,老是包错误,能不能告诉下解决方法啊
sxfcct 2012-03-02
  • 打赏
  • 举报
回复
呵呵,上面的是解压缩文件用的,不能用来直接操作数据,还是很感谢
frant 2012-03-01
  • 打赏
  • 举报
回复
public static bool UnZip(Stream zipfilestren, string directoryName, string password,string strTotal)
{
bool ret = true;
try
{
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

{
ZipInputStream s = new ZipInputStream(zipfilestren);

if (password != null && password.Length > 0)
s.Password = password;

BinaryReader reader = new BinaryReader(s);
ZipEntry theEntry;
long sizezip = 0;

while ((theEntry = s.GetNextEntry()) != null)
{
string fileName = theEntry.Name;
if (fileName != String.Empty)
{
if (theEntry.CompressedSize == 0)
continue;
if (!theEntry.IsFile)
{
continue;
}
else if (!theEntry.IsCompressionMethodSupported())
{
continue;
}
else if (!theEntry.CanDecompress)
{
continue;
}

String fullFileName = directoryName + "/" + fileName;

//String path = fullFileName.Substring(0, fullFileName.LastIndexOf(PathSeperater));
if (!file.DirectoryExists(directoryName))
{
file.CreateDirectory(directoryName);
}
using (IsolatedStorageFileStream stream = file.CreateFile(fullFileName))
{
BinaryWriter writer = new BinaryWriter(stream);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = reader.Read(data, 0, data.Length);
sizezip += size;
if (size > 0)
{ writer.Write(data, 0, size); }
else
{ break; }
}

writer.Close();
stream.Close();
double dvalue = (double)(sizezip / 1024);
dvalue /= 1024;
double dtotal = Double.Parse(strTotal);
dvalue /= (2*dtotal);
App.model[0].ProbarValue = Convert.ToInt32(dvalue*100);//绑定的进度条的值
App.model[0].ProbarCount = Convert.ToInt32(dvalue * 100) + "%";//绑定进度条%比
}

}
}

s.Close();
}

}
catch (Exception ex)
{
ret = false;
}
return ret;
}


这是本人项目中用的解压代码,我现在问题是解压时,界面卡住并且根据文件大小耗时比较严重

压缩用 : ZipOutputStream s = new ZipOutputStream(File.Open(ZipedFileName, FileMode.OpenOrCreate)); 我这里只用解压,压缩没有仔细看
DrSmart 2012-02-29
  • 打赏
  • 举报
回复
直接流操作的吧,没用过sharpXXX,能移植个zlib更好

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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