首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解压缩文件的Monotouch - ICSharpCode.SharpZipLib

解压缩文件的Monotouch - ICSharpCode.SharpZipLib
EN

Stack Overflow用户
提问于 2011-02-01 11:20:37
回答 1查看 2.8K关注 0票数 1

我使用ICSharpCode.SharpZipLib解压一个包含文件、文件夹和子文件夹的文件,但我收到了一个错误,我在这里或任何其他论坛中都找不到这个错误。

代码:

代码语言:javascript
复制
public static void UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile)
{
        ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
        if (password != null && password != String.Empty)
            s.Password = password;
        ZipEntry theEntry;
        string tmpEntry = String.Empty;
        while ((theEntry = s.GetNextEntry()) != null)
        {
            string directoryName = outputFolder;
            string fileName = Path.GetFileName(theEntry.Name);
            // create directory 
            if (directoryName != "")
            {
                Directory.CreateDirectory(directoryName);
            }
            if (fileName != String.Empty)
            {
                if (theEntry.Name.IndexOf(".ini") < 0)
                {
                    string fullPath = directoryName + "\\" + theEntry.Name;
                    fullPath = fullPath.Replace("\\ ", "\\");
                    string fullDirPath = Path.GetDirectoryName(fullPath);
                    if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
                    FileStream streamWriter = File.Create(fullPath);
                    int size = 2048;
                    byte[] data = new byte[2048];
                    while (true)
                    {
                        size = s.Read(data, 0, data.Length);
                        if (size > 0)
                        {
                            streamWriter.Write(data, 0, size);
                        }
                        else
                        {
                            break;
                        }
                    }
                    streamWriter.Close();
                }
            }
        }
        s.Close();
        if (deleteZipFile)
        {
            File.Delete(zipPathAndFile);

        }
}

获取错误:

代码语言:javascript
复制
Unhandled Exception: ICSharpCode.SharpZipLib.SharpZipBaseException: Unknown block type 6
  at ICSharpCode.SharpZipLib.Zip.Compression.Inflater.Decode () [0x00000] in <filename unknown>:0 
  at ICSharpCode.SharpZipLib.Zip.Compression.Inflater.Inflate (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at ICSharpCode.SharpZipLib.Zip.ZipInputStream.BodyRead (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at ICSharpCode.SharpZipLib.Zip.ZipInputStream.InitialRead (System.Byte[] destination, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at ICSharpCode.SharpZipLib.Zip.ZipInputStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at ICSharpCode.SharpZipLib.Zip.ZipInputStream.CloseEntry () [0x00000] in <filename unknown>:0Error connecting stdout and stderr (127.0.0.1:10001)

  at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry () [0x00000] in <filename unknown>:0 
  at FolderNavigation.ZipController.UnZipFiles (System.String zipPathAndFile, System.String outputFolder, System.String password, Boolean deleteZipFile) [0x00119] in /Users/claudio/Projects/FolderNavigation/FolderNavigation/ZipController.cs:15 
  at FolderNavigation.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0005e] in /Users/claudio/Projects/FolderNavigation/FolderNavigation/Main.cs:43 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:31 
  at FolderNavigation.Application.Main (System.String[] args) [0x00000] in /Users/claudio/Projects/FolderNavigation/FolderNavigation/Main.cs:14 

有什么想法吗?

致以敬意,

克劳迪奥

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-01 21:53:00

例如,你有没有尝试过在windows中通过.NET上的代码来解压缩文件?也许这个文件被SharpZipLib不支持的一些技术压缩了?

我的判断是,错误发生在'ICSharpCode.SharpZipLib.Zip.Compression.Inflater.Decode‘方法中,如果你检查SharpZipLib的源代码,它只解码压缩字节的数组。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4858540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档