2011-12-01 25 views
1

我使用7zip sdk(http://www.7-zip.org/sdk.html)來壓縮一個文件文件。使用7zip sdk來壓縮文件,但歸檔文件不是原來的,並且不能使用unrar來解壓縮

它使用這種包裝工作正常:

public void EncodeSingleFile(FileStream inStream, FileStream outStream) { 
    bool eos = false; 
    Int32 dictionary = 1 << 21; 
    Int32 posStateBits = 2; 
    Int32 litContextBits = 3; // for normal files 
    // UInt32 litContextBits = 0; // for 32-bit data 
    Int32 litPosBits = 0; 
    // UInt32 litPosBits = 2; // for 32-bit data 
    Int32 algorithm = 2; 
    Int32 numFastBytes = 128; 
    string mf = "bt4"; 

    propIDs = new CoderPropID[] 
     { 
      CoderPropID.DictionarySize, 
      CoderPropID.PosStateBits, 
      CoderPropID.LitContextBits, 
      CoderPropID.LitPosBits, 
      CoderPropID.Algorithm, 
      CoderPropID.NumFastBytes, 
      CoderPropID.MatchFinder, 
      CoderPropID.EndMarker 
     }; 
    properties = new object[] 
     { 
      dictionary, 
      posStateBits, 
      litContextBits, 
      litPosBits, 
      algorithm, 
      numFastBytes, 
      mf, 
      eos 
     }; 

    Encoder encoder = new Encoder(); 
    encoder.SetCoderProperties(propIDs, properties); 
    encoder.WriteCoderProperties(outStream); 
    Int64 fileSize = inStream.Length; 
    for (int i = 0; i < 8; i++) 
    { 
     outStream.WriteByte((Byte) (fileSize >> (8*i))); 
    } 
    encoder.Code(inStream, outStream, -1, -1, null); 

}

不過,我有一個問題:

我只能利用7-zip.org安裝7zip的外殼解壓,不能用unrar解壓縮。如果我設置了一些參數,那麼它可能會與unrar一起工作嗎?

如果我打開7zip的文件,並檢查屬性,我得到:

  • 名稱:abc.pdb
  • 尺寸:1 809 920
  • 包裝尺寸:249 305
  • 方法:LZMA:21
  • 類型:LZMA
+0

如果您在7-Zip中打開您的檔案,並檢查屬性,它對「類型」說什麼? – Cylindric

+0

我更新了我的問題中的信息,它是:lzma – olidev

+0

如果我使用7zip shell進行壓縮,則7zip文件的類型爲:7z。哼哼,奇怪....你有什麼想法我做錯了什麼? – olidev

回答

1

在CodeProject上有一個人爲使用SDK爲7z創建一個C#接口的例子。他還提到現在可以使用COM來對付DLL,但我不知道它是如何工作的。在代碼項目中檢出C# (.NET) Interface for 7-Zip Archive DLLs

+0

這是與DLL,我想避免,所以我去使用SDK。它工作到目前爲止,但問題是,它不能用winrar解壓縮。我正在努力解決這個問題。謝謝 – olidev

0

如果您正在尋找創建一個RAR壓縮包,你可能不太好,因爲它是封閉的。您可以使用外部庫,但壓縮算法是專有的。

RAR Wiki Page

RAR文件只能與商業軟件的WinRAR,RAR創建,並有權從許可軟件亞歷山大·羅肖爾

我會建議調查的一個許多沒有阻礙的替代品。

+0

不行,目的就是讓它變成7z。但問題是我從sdk得到的結果無法使用winrar解壓縮。如果我使用7z的shell執行壓縮。然後,我可以使用winrar解壓縮 – olidev

+0

啊,那麼就夠了。我想也許它是使用WinRAR不理解的7-zip格式的變體。我不認爲「不使用WinRAR」是一種選擇? :) – Cylindric

+0

它*有*爲7z格式嗎?我已經使用[Ionic DotNetZip](http://dotnetzip.codeplex。com /)庫取得巨大成功,但它創建了zip壓縮文件。 – Cylindric

相關問題