SevenZipSharp CompressStreamDictionary Error


小于

大约 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(Object sender, DoWorkEventArgs e(

我遇到了同样的问题,并像这样解决它:

在这里下载七拉链叉: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 的文件对其进行了测试,没有错误。我将把代码提交给七zipsharp作者,以将其包含在源代码中。


旧答案:

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

下载此补丁并应用于SevenZipSharp源代码。这将使它完全多线程感知。

您也可以尝试替换 7zip 库,提供 sevenzipsharp 软件包,官方库可在 http://www.7-zip.org/download.html

下载

注意:您会在下载的存档中找到7za.dll,这是库的轻量级版本,仅支持.7z格式(没有zip...

最新更新