Adding large files to IO.Compression.ZipArchiveEnt

2019-06-23 17:42发布

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条回答
该账号已被封号
2楼-- · 2019-06-23 18:11

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.

查看更多
登录 后发表回答