I keep getting a very annoying OutOfMemory exception on the following code.
I'm zipping a lot of small files (PDF, each being 1.5mb approx).
At first I was getting the exception afer 25 files zipped, which doesn't seem like a massing archive.
Setting up the size of the ZipEntry somehow helped since now I manage to get up to 110 files zipped (I'm debugging under visual studio)
Here's my code, maybe there's something wrong with it.
Any help would be greatly appreciated.
Thanks
public static MemoryStream Zip(Dictionary<string, byte[]> files)
{
var outputMemStream = new MemoryStream();
var zipStream = new ZipOutputStream(outputMemStream);
zipStream.SetLevel(9);
foreach (var file in files)
{
zipStream.PutNextEntry(new ZipEntry(file.Key.FmtValidFileName())
{
Size = file.Value.Length
});
zipStream.Write(file.Value, 0, file.Value.Length);
zipStream.Flush();
}
zipStream.Finish();
outputMemStream.Position = 0;
return outputMemStream;
}