2013-04-04 131 views
1

我有一個當前進程提取tar.gz,但當前進程無法處理超過4GB ......我想知道我在做什麼錯誤,導致我使用sharpzip LIB它說,參數的長度不能小於零....所有的註釋掉的代碼是當前進程24GB tar.gz使用sharpziplib解壓縮

請參閱下面的代碼,給我方向

public static void ExtractTarGZFiles(string strExtractionPath, string strInboundFolder) 
    { 
     List<string> files = new List<string>(); 
     string strFile = Path.GetFullPath(ConfigurationManager.AppSettings["InboundFolderPath"].ToString()); 
     if (mblnRunForFile) 
     { 
      System.IO.FileInfo ioInfo = new FileInfo(mstrFilename); 
      strFile = ioInfo.DirectoryName; 
      files.Add(ioInfo.Name); 

     } 
     else 
     { 
      files = System.IO.Directory.GetFiles(ConfigurationManager.AppSettings["InboundFolderPath"], "*.gz").ToList(); 
     } 

     foreach (string file in files) 
     { 
      try 
      { 
      //string stFilePath = file; 
      //string testingthisdamnthing = strInboundFolder + mstrFilename; 
      //FileStream xstream = new FileStream(stFilePath, FileMode.Open, FileAccess.Read, FileShare.None); 
      //xstream.Close(); 
      //string strTemp = ConfigurationManager.AppSettings["ExtractTempFolderPath"]; 
      //TarArchive objTA = TarArchive.CreateInputTarArchive(new GZipStream(new FileStream(stFilePath, FileMode.Open, FileAccess.Read), CompressionMode.Decompress)); 
      //objTA.ProgressMessageEvent += ExtractTarNotifier; 
      //objTA.ExtractContents(strTemp); 



      //DirectoryInfo dirtemp = new DirectoryInfo(strTemp); 
      DirectoryInfo dirExtract = new DirectoryInfo(strExtractionPath); 

      Stream inStream = File.OpenRead(stFilePath); 
      Stream gzipStream = new GZipInputStream(inStream); 

      TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream); 
      tarArchive.ExtractContents(ConfigurationManager.AppSettings["ExtractFolderPath"]); 
      tarArchive.Close(); 

      gzipStream.Close(); 
      inStream.Close(); 
      //while (IsFileExistsinTempPath(dirtemp, dirExtract)) 
      //{ 
      // //Do nothing 
      //} 
      //CopyFilesFromTempToExtract(dirtemp, dirExtract); 
      //objTA.Close(); 
      //Logger.Write(" Tar.Gz files Decompressed Successfully"); 
      MonthLog.Log("Tar.Gz files Decompressed Successfully", "Month", 3, 2, System.Diagnostics.TraceEventType.Information, mstrFilename); 
      System.IO.File.Copy(stFilePath, ConfigurationManager.AppSettings["ArchiveFolderPath"] + new FileInfo(stFilePath).Name, true); 
      File.Delete(stFilePath); 
      //Logger.Write(" Tar.GZ files Moved to Archive Folder"); 
      MonthlyGreenPackageLog.Log("Tar.Gz files Moved to Archive Folder", "Month", 3, 2, System.Diagnostics.TraceEventType.Information, mstrFilename); 

      } 
       catch (System.IO.IOException ex) 
       { 
        //go to next file 
        //Logger.Write("Unable to open compressed file"); 
        MonthLog.Log("Unable to open compressed file", "Month", 1, 1, System.Diagnostics.TraceEventType.Error, mstrFilename); 
        Email objEmail1 = new Email(); 
        objEmail1.IsBodyHTML = true; 
        objEmail1.FromAddress = ConfigurationManager.AppSettings["FromAddress"]; 
        string[] strToAddresses = ConfigurationManager.AppSettings["ExceptionAddress"].Split(','); 
        objEmail1.SetToAddress(strToAddresses); 
        objEmail1.Subject = "The Month File " + mstrFilename + " Failed to Decompress "; 
        objEmail1.Body = " Exception " + ex.Message + " occured while decompressing file"; 
        //objEmail.AddAttachment("Exception occured while processingfiles"); 
        objEmail1.SendEmail(); 
        //Logger.Write("Sent a mail to all the Address"); 
        throw ex; 
       } 
       catch (Exception ex) 
       { 
        //Logger.Write("Exception " + ex.Message + " occured while decompressing file"); 
        MonthlyGreenPackageLog.Log("Exception " + ex.Message + " occured while decompressing file", "Monthl", 1, 1, System.Diagnostics.TraceEventType.Error, mstrFilename); 
        Email objEmail = new Email(); 
        objEmail.IsBodyHTML = true; 
        objEmail.FromAddress = ConfigurationManager.AppSettings["FromAddress"]; 
        string[] strToAddresses = ConfigurationManager.AppSettings["ExceptionAddress"].Split(','); 
        objEmail.SetToAddress(strToAddresses); 
        objEmail.Subject = "The tar.gz Month File " + mstrFilename + " Failed to Decompress "; 
        objEmail.Body = " Exception " + ex.Message + " occured while decompressing file"; 
        //objEmail.AddAttachment("Exception occured while processing ADX files"); 
        objEmail.SendEmail(); 
        //Logger.Write("Sent a mail to all the Address"); 
        throw ex; 
       } 

      } 
     } 
+0

你把它編譯爲x86或x64嗎? – Middas 2013-04-04 18:16:53

+0

在X86機器上, – user2133071 2013-04-04 18:21:50

+0

然後你需要弄清楚如何將你的文件分解成4GB的塊,你需要64位來玩更多。 – Middas 2013-04-04 18:22:52

回答

0

我對你有三個潛在的解決方案,但我不能告訴你是否有任何人會實際工作。

  1. 使用Unzip from Stream示例通過內存進行流式傳輸,因此您永遠不需要加載整個事物(這就是現在它失敗的原因)。
  2. 切換到使用DotNetZip,這可能有更多的選項來處理x86機器上的大文件。
  3. 查找可以編寫腳本或可以監視目錄的常規unzipper應用程序,並在它到達您的應用程序之前將其解壓縮。
+0

我不認爲這是一個內存問題,有些描述符字段有可能是64位,其中一個字段的第31位= 1,所以當解釋爲int32時,它變爲負數 – 2013-04-04 18:40:26

+0

您是否使用過7zip命令行?這是如何與x命令一起工作的。? – user2133071 2013-04-04 19:37:00

+0

@ user2133071 - 我沒有自己,但[這個鏈接](http://www.dotnetperls.com/7-zip-examples)有一些很好的細節 – Bobson 2013-04-04 20:24:11

0

如果你有你應用程序爲x86,那麼每個進程只能有4GB的內存。將其編譯爲x64以使用更多資源。

+1

如果機器不是x64也沒有幫助。 – Bobson 2013-04-04 18:28:27

0

這是來自您正在使用的ZipLibrary。您需要將應用程序編譯爲x64程序並在64位環境中運行它。

// To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code, 
    // you need to do one of the following: Specify UseZip64.Off, or set the Size. 
    // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either, 
    // but the zip will be in Zip64 format which not all utilities can understand.