-1

When I want to Compress the Large files (ex: an iso file about 2GB) using .net System.IO.Compress, It will show Exception and stop working.

It my Code:

 using (ZipArchive zipArchive = ZipFile.Open(zipFile, ZipArchiveMode.Update))
            {
                zipArchive.CreateEntryFromFile(@"C:\test1.iso", "test1.iso", CompressionLevel.NoCompression);
                zipArchive.CreateEntryFromFile(@"C:\test2.iso", "test2.iso", CompressionLevel.NoCompression);
            }

Exception:

An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll

How can I do to slove this problem in x86 system? (in x64 it can run,but my app will be x86 app).

Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52
  • See this post http://stackoverflow.com/questions/16585488/writing-to-ziparchive-using-the-httpcontext-outputstream – Sievajet Sep 03 '15 at 06:22

2 Answers2

0

You will need to use the ZipArchive class instead and the get or create a ZipArchiveEntry for each file. That has an Open() method that returns a Stream you can then write to. You may then have to read from the iso and write to the zip entry in smallish chunks (say, 64MB) to keep memory use down.

Note: I'm on the go so have not been able to test this; it's not impossible that this method will also crash, depending on the internals of ZipArchive.

Zastai
  • 1,115
  • 14
  • 23
0

First Create List to Save item on Ziplist. Sec. ZipArchiveMode change use create. Thir. foreach all item in Ziplist,to CreateEntryFromFile in saveZipPath.