2011-02-01 42 views
1

ICSharpCode.SharpZipLibを使用して、ファイル、フォルダ、サブフォルダが入っているファイルを解凍しますが、私はここや他のフォーラムで見つけられなかったエラーを受け取ります。モノトゥッチ - 解凍ファイルのICSharpCode.SharpZipLib

コード:

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); 

     } 
} 

エラーが得た:

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 

任意のアイデア?

よろしく、
クラウディオ

答えて

1

あなたはたとえば、Windowsで.NETのコードを経由してファイルを解凍しようとしたことがありますか? sharpZipLibがサポートしていないいくつかのテクニックでファイルが圧縮されている可能性がありますか?

「ICSharpCode.SharpZipLib.Zip.Compression.Inflater.Decode」メソッドでエラーが発生すると判断しました.SharpZipLibのソースコードをチェックすると、収縮したバイトの配列がデコードされます。

+0

はい、それは正しいです。私は、このzipファイルをダウンロードしたときにエラーが発生していることを理解しました。私は地元のzipファイルで試してみましたが、うまくいきました。 – Claudio

関連する問題