I've been knocking my head on this for 2 days. We're using 7ZipSharp to create .7z files from several source files (incoming emails in fact).
In order to optimize the application, I want to avoid hard disk access so I switched to the CompressStreams function family.
The code using filenames instead of Streams works perfectly. When switching to Streams, I get the "KeyNotFoundException", only when CompressionMode = Append.
My test code:
for (var i = 0; i < numFiles; i++)
{
//if(i > 0)
// compressor.CompressionMode = CompressionMode.Append;
Console.WriteLine("Adding copy num " + (i + 1) + " to the archive");
SevenZipUtil.AddStream(File.OpenRead(sampleFile), "email-" + i + ".eml", outFile);
}
Helper method code:
public static void AddStream(Stream inStream, string fileName, string destinationFile)
{
SevenZipCompressor comp = new SevenZipCompressor();
comp.ArchiveFormat = OutArchiveFormat.SevenZip;
comp.CompressionLevel = CompressionLevel.Ultra;
if(File.Exists(destinationFile))
{
comp.CompressionMode = CompressionMode.Append;
}
FileStream outStream = File.OpenWrite(destinationFile);
comp.DefaultItemName = fileName;
comp.CompressStream(inStream, outStream);
outStream.Flush();
outStream.Close();
}
Error source is file LibraryManager.cs, method InArchive, line 428.
if (_inArchives[user][format] == null
To summarize:
- Appending with files instead of Streams, OK
- CompressStream in mode = Create, OK
- Afterwards, CompressStream in mode = Append fails.
Has anyone any working code of adding several streams to a .7z file, or may this be a bug I should post to the SevenZipSharp forum?
Thanks,