简体   繁体   中英

.net C# zipArchive CreateEntryFromFile largesize will be OutOfMemoryException

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).

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM