本文介绍了使用7zip sdk压缩文件,但存档文件不是原始文件,无法使用unrar解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

}

但是,我有一个问题:

我只能使用从7-zip.org安装的7zip shell解压缩它,而不能用unrar解压缩。

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?

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

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


  • 名称:abc.pdb

  • 大小:1809920

  • 包装大小:249305

  • 方法:LZMA:21

  • 类型:lzma

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

推荐答案

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

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.

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

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

这篇关于使用7zip sdk压缩文件,但存档文件不是原始文件,无法使用unrar解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!