2011-02-01 5 views
1

파일, 폴더 및 하위 폴더가 포함 된 파일의 압축을 풀기 위해 ICSharpCode.SharpZipLib을 사용하고 있지만 여기 또는 다른 포럼에서 찾지 못한 오류가 발생합니다. .Monotouch - 압축 해제 파일 용 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

는 예를 들어 창에서 .NET의 코드를 통해 파일을 압축 해제하려고 있나요? 파일이 SharpZipLib에서 지원하지 않는 일부 기술로 압축되어있을 수 있습니까?

'ICSharpCode.SharpZipLib.Zip.Compression.Inflater.Decode'메서드에서 오류가 발생한다는 것을 판단합니다.이 메서드는 SharpZipLib의 소스 코드를 확인하면 압축 된 바이트의 배열을 디코딩합니다.

+0

예, 그렇습니다. 나는이 zip 파일을 다운로드 할 때 오류가 있다는 것을 알아 냈습니다. 로컬 zip 파일을 사용해 보았지만 정상적으로 작동했습니다. – Claudio