There is a client requirement to create a zip which consist of multiple files placed inside tree-like structured folders. It contains upto 150 files at maximum. When these files exceed approximately 160MB in memory stream OutOfMemoryException is thrown.
- List item
- Is there a config to increase memory allocated to this operation?
- Any other alternative ways to solve this?
Sample code
MemoryStream memStream = new MemoryStream();
using (var zipStream = new ZipOutputStream(memStream))
{
foreach (FileModel fileToBeAddedInZip in listOfFiles)
{
byte[] fileBytes;
fileBytes = //Read the file from DB
ZipEntry fileEntry = null;
fileEntry = new ZipEntry(fileToBeAddedInZip.fileName)
{
Size = fileBytes.Length
};
zipStream.PutNextEntry(fileEntry);
zipStream.Write(fileBytes, 0, fileBytes.Length);
}
}
zipStream.Flush();
zipStream.Close();