Adding large files to IO.Compression.ZipArchiveEntry throws OutOfMemoryException Exception

梦想的初衷 提交于 2019-12-10 17:23:26

问题


I am trying to add a large video file(~500MB) to an ArchiveEntry by using this code:

using (var zipFile = ZipFile.Open(outputZipFile, ZipArchiveMode.Update))
{
    var zipEntry = zipFile.CreateEntry("largeVideoFile.avi");
    using (var writer = new BinaryWriter(zipEntry.Open()))
    {
        using (FileStream fs = File.Open(@"largeVideoFile.avi", FileMode.Open))
        {
            var buffer = new byte[16 * 1024];
            using (var data = new BinaryReader(fs))
            {
                int read;
                while ((read = data.Read(buffer, 0, buffer.Length)) > 0)
                {
                    writer.Write(buffer, 0, read);
                }
            }
        }
    }
}

I am getting the error

System.OutOfMemoryException

when writer.Write is called, alltought I used a intermediate buffer....

Any idea how to solve this?


回答1:


Build the application as any CPU and execute it in a x64 machine. This should fix the issue. (Or directly build the application as x64).

Videos normally cannot be compressed a lot and the zip file probably remains in memory until the are completely created.



来源:https://stackoverflow.com/questions/28360775/adding-large-files-to-io-compression-ziparchiveentry-throws-outofmemoryexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!