添加大文件IO.Compression.ZipArchiveEntry抛出OutOfMemoryException异常 [英] Adding large files to IO.Compression.ZipArchiveEntry throws OutOfMemoryException Exception
问题描述
我试图通过使用此代码添加一个大的视频文件(〜500MB)到ArchiveEntry:
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);
}
}
}
}
}
我收到错误
的System.OutOfMemoryException
System.OutOfMemoryException
当writer.Write被调用,alltought我用了一个中间缓冲区....
when writer.Write is called, alltought I used a intermediate buffer....
不知道如何解决这个问题?
Any idea how to solve this?
推荐答案
构建应用程序的任何CPU,并在64位计算机上执行它。这应该可以解决这个问题。 (或者直接构建应用程序为64位)。
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).
视频通常不能被压缩了很多,zip文件可能保留在内存中,直到完全建立。
Videos normally cannot be compressed a lot and the zip file probably remains in memory until the are completely created.
这篇关于添加大文件IO.Compression.ZipArchiveEntry抛出OutOfMemoryException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!