Memorystreams smaller than about 16 MB are working well. But I get an error (HResult = -2146233088) when compressing a memory stream which size is over about 16MB. How can I get it to work?
I use SevenZipSharp.dll Version 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, "");
}
The execution has failed due to the bug in the SevenZipSharp. Please report about it to http://sevenzipsharp.codeplex.com/WorkItem/List.aspx, post the release number and attach the archive.
Error Stacktrace:
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)
I had the same problem and solve it like this:
Download the sevenzipsharp fork here: https://github.com/StevenBonePgh/SevenZipSharp This is a recent version with lot of bug fixes, but the CompressStreamDictionary Error is still there (as of today).
To fix the memory problem, you must specify a lower dictionary size. The bigger the file to compress, the lower the disctionary size. This is done like this:
It seems 26 is the default value. I made some tests and did a small formula to adapt dictionary size to the stream size:
I tested it with files from 16MB to 8GB with no errors. I will submit the code to the sevenzipsharp author to include it in source code.
Old answer:
Afaik, this project is abandonware. I also has some errors using it in a multithread environment and the following solution seems to improve things:
Download this patch and apply to SevenZipSharp source code. This will make it fully multithread aware.
You can also try to replace 7zip Library, provided with sevenzipsharp package, with the official lib downloadable at http://www.7-zip.org/download.html
Note: you will find 7za.dll in the downloaded archive, this is the light version of the library wich only support .7z format (no zip...).