使用7zip sdk压缩文件,但压缩文件不是原来的文件,无法使用unrar解压

发布于 2024-12-18 17:45:45 字数 1732 浏览 3 评论 0原文

我正在使用 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

I am using 7zip sdk (http://www.7-zip.org/sdk.html) to compress a file.

it works fine using this wrapper:

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

}

However, I have got a problem:

I can only decompress it using 7zip shell installed from 7-zip.org, can not decompress with unrar. is that possible if I set some parameters and it will work with unrar as well?

If I open the file in 7zip and check the properties, I got:

  • Name: abc.pdb
  • Size: 1 809 920
  • Packed Size: 249 305
  • Method: LZMA:21
  • Type: lzma

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懒猫 2024-12-25 17:45:45

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

查看代码上的 7-Zip 存档 DLL 的 C# (.NET) 接口项目。

There is an example on CodeProject of someone creating a C# interface for 7z using the SDK. He also mentions it is now possible to use COM against the DLL's, but I don't know how that works.

Check out C# (.NET) Interface for 7-Zip Archive DLLs on The Code Project.

只等公子 2024-12-25 17:45:45

如果您想要创建 RAR 存档,您可能会不走运,因为它是闭源的。您可能可以使用外部库,但压缩算法是专有的。

来自 RAR Wiki 页面

RAR 文件只能使用商业软件 WinRAR、RAR 以及获得许可方 Alexander Roshal 许可的软件创建

。我建议您研究众多不受阻碍的替代方案之一。

If you are looking to create a RAR archive, you may be out of luck, as it is closed-source. You can probably use external libraries, but the compression algorithm is proprietary.

From the RAR Wiki Page:

RAR files may be created only with commercial software WinRAR, RAR, and software that has permission from the licensor Alexander Roshal

I would recommend investigating one of the many unencumbered alternatives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文