zoukankan      html  css  js  c++  java
  • windows phone使用sharpcompress进行解压压缩文件

    在做移动端时,当我们需要从服务器获得多个文件时,为了节约流量,服务器一般会返回一个压缩包,那我们就是下载完成后,在手机中进行解压到指定位置

    SharpCompress就是可以在手机中进行解压一个类库(.net),在codeplex是开源,支持桌面端和移动端

         点击下载最新版本       查看支持内容      API使用示例

    下面我们看一下在windows phone中使用其进行解压ZIP包

            public async void DownloadAndUnCompress()
            {
                string strUrl = "http://qd.baidupcs.com/file/3ebe6e988584733fba61c04e9568bc73?fid=3860865449-250528-923682234289515&time=1401003314&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-sDvdhrr7p1EWhMUFNOaYlQbwLmE%3D&to=qb&fm=Q,B,U,nc&newver=1&expires=1401003914&rt=sh&r=347257022&logid=3996325361&sh=1&vuk=3860865449&fn=SharpCompress0.10.3.zip";
    
                await Task.Run(() =>
                 {
                     WebClient wc = new WebClient();
                     wc.OpenReadAsync(new Uri(strUrl, UriKind.Absolute));
                     wc.DownloadProgressChanged += (s, dpce) =>
                     {
                         System.Diagnostics.Debug.WriteLine("已下载" + dpce.ProgressPercentage + "%");
                     };
    
                     wc.OpenReadCompleted += (s, orce) =>
                     {
                         if (orce.Error != null)
                         {
                             System.Diagnostics.Debug.WriteLine("下载出错");
                             return;
                         }
    
                         using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                         {
                             var zipArchive = ArchiveFactory.Open(orce.Result);//创建一个解压器
                             foreach (var entry in zipArchive.Entries)//提取里面每个实体,包括文件夹都算实体
                             {
                                 //如果为文件夹先把文件夹创建出来
                                 if (entry.IsDirectory)
                                 {
                                     if (!storage.DirectoryExists(entry.FilePath))
                                     {
                                         storage.CreateDirectory(entry.FilePath);
                                     }
                                     continue;
                                 }
                                 //entry.FilePath  为文件的全路径
                                 using (IsolatedStorageFileStream isofilestream = storage.CreateFile(entry.FilePath))
                                 {
                                     //写入到独立存储空间中
                                     entry.WriteTo(isofilestream);
                                 }
                             }
                             zipArchive.Dispose();
                             System.Diagnostics.Debug.WriteLine("解压完成");
                         }
                     };
                 });
            }

    其它的如RAR、Tar、GZip、7Zip可参考codeplex官方文档

  • 相关阅读:
    数据库操作相关(sql语句-命令行)
    五月份和六月份的总结
    解决IE6下透明图片有背景的问题
    LceMeaning专用函数集《Lcemeaning》
    Delphi获得与设置系统时间格式《转》
    Delphi 调用Excel《转》
    调用外部程序并等待程序运行结束《Lcemeaning》
    如何获取Memo的行数与列数《转》
    delphi小写金额转大写的函数《转》
    delphi中的时间函数运算《转》
  • 原文地址:https://www.cnblogs.com/LeeYZ/p/3751286.html
Copyright © 2011-2022 走看看