c# - 使用 7zip sdk 压缩文件,但存档文件不是原始文件,无法使用 unrar 解压缩

标签 c# 7zip

我正在使用 7zip sdk (http://www.7-zip.org/sdk.html) 来压缩文件。

使用这个包装器效果很好:

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 shell解压,不能用unrar解压。如果我设置一些参数并且它也可以与 unrar 一起使用,这可能吗?

如果我在 7zip 中打开文件并检查属性,我得到:

  • 姓名:abc.pdb
  • 大小:1 809 920
  • 包装尺寸:249 305
  • 方法:LZMA:21
  • 类型:lzma

最佳答案

CodeProject 上有一个示例,其中有人使用 SDK 为 7z 创建了 C# 界面。他还提到现在可以针对 DLL 使用 COM,但我不知道它是如何工作的。

查看 C# (.NET) Interface for 7-Zip Archive DLLs在代码项目上。

关于c# - 使用 7zip sdk 压缩文件,但存档文件不是原始文件,无法使用 unrar 解压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8340636/

相关文章:

cryptography - 7-zip 如何检查您提供的密码是否正确?

c# - 如何获取 7-zip 存档中打包文件的大小

c# - Return (null) 而不是 return null - 为什么要加括号?

c# - 为什么 Swashbuckle.aspnet.core.swagger 不被识别

c# - 替代接口(interface)的静态方法

c# - htmlagilitypack 获取具有内容属性的元标记

c# - 如何在 C# 类中实现 List<T> 属性?

linux - 通过 ssh 在远程机器上运行 7z

java - 无法使用 java 解压文件,但可以使用 7zip 解压文件

java - 加载库 jar 时出错