首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

WP7下怎么将数据用zip压缩和解压缩

2013-02-24 
WP7上如何将数据用zip压缩和解压缩SharpZipLib中的zip压缩都是将文件进行压缩和解压缩(文件在压缩包中有一

WP7上如何将数据用zip压缩和解压缩
SharpZipLib中的zip压缩都是将文件进行压缩和解压缩(文件在压缩包中有一个entry),如何直接将内存中的数据进行zip压缩呢(不需要entry)?
[解决办法]
直接流操作的吧,没用过sharpXXX,能移植个zlib更好
[解决办法]
 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)); 我这里只用解压,压缩没有仔细看
               

热点排行