1

小于约 16 MB 的内存流运行良好。但是在压缩大小超过 16MB 的内存流时出现错误(HResult = -2146233088)。我怎样才能让它工作?

我使用 SevenZipSharp.dll 版本 0.64.3890.29348

SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
 compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
 compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra;
 compressor.EncryptHeaders = false;

 using (Stream output = File.Open(sFileName, FileMode.Create))
 {
     ms.Position = 0;
     compressor.CompressStreamDictionary(new Dictionary<string, Stream> { { zipFileName, ms } }, output, "");
 }

由于 SevenZipSharp 中的错误,执行失败。请向http://sevenzipsharp.codeplex.com/WorkItem/List.aspx报告,发布版本号并附上存档。

错误堆栈跟踪:

bei SevenZip.SevenZipBase.ThrowException(CallbackBase handler, Exception[] e) bei SevenZip.SevenZipBase.CheckedExecute(Int32 hresult, String message, CallbackBase handler) bei SevenZip.SevenZipCompressor.CompressStreamDictionary(Dictionary`2 streamDictionary, Stream archiveStream, String password) bei frmConfigSystem.bwExport_DoWork(对象发送者,DoWorkEventArgs e)

4

1 回答 1

1

我有同样的问题并像这样解决它:

在此处下载 Sevenzipsharp 分支:https ://github.com/StevenBonePgh/SevenZipSharp 这是一个最新版本,修复了很多错误,但 CompressStreamDictionary 错误仍然存​​在(截至今天)。

要解决内存问题,您必须指定较小的字典大小。要压缩的文件越大,字典大小越小。这样做是这样的:

szc.CustomParameters.Add("d", 22);

似乎 26 是默认值。我做了一些测试并做了一个小公式来使字典大小适应流大小:

                if (!Environment.Is64BitProcess)
                {
                    if (stream.Length>=16*1024*1024)
                    {
                        int sizeG = (int)(stream.Length / 1024 / 1024 / 1024);
                        int param;

                        // from 16MB to 2GB: use 23
                        if (sizeG <= 2)
                        {
                            param = 23;
                        }
                        else
                        {
                            // from 2GB : use 24 - size(GB)
                            param = Math.Max(24 - sizeG, 1);
                        }
                        szc.CustomParameters.Add("d", param.ToString());
                    }
                }

我用 16MB 到 8GB 的​​文件对其进行了测试,没有任何错误。我会将代码提交给sevenzipsharp作者,以将其包含在源代码中。


老答案:

Afaik,这个项目是废弃软件。我在多线程环境中使用它也有一些错误,以下解决方案似乎可以改善一些事情:

下载此补丁并应用于 SevenZipSharp 源代码。这将使其完全支持多线程。

您也可以尝试使用可在http://www.7-zip.org/download.html下载的官方 lib 替换随 Sevenzipsharp 包提供的 7zip 库

注意:您会在下载的存档中找到 7za.dll,这是该库的精简版,仅支持 .7z 格式(无 zip...)。

于 2015-03-18T10:25:56.740 回答