.net 使用BZip2(SharpZipLib)的OutOfMemoryException
我使用Asp.net、.NET3.5、win2003、iis 6.0 我使用Oracle收集文件,将文件以SharpZipLib.BZip2压缩格式保存在Oracle表中的字段RAW中 我的应用程序是Web,我使用WCF服务获取文件的数据(字节数组)。aspx页面向用户发送文件(下载文件) 我的问题是: 我从Oracle读取数据(我调用WCF服务)。我得到字节数组(字节[]) 我尝试使用SharpZipLib.BZip2解压文件.net 使用BZip2(SharpZipLib)的OutOfMemoryException,.net,stream,bytearray,out-of-memory,sharpziplib,.net,Stream,Bytearray,Out Of Memory,Sharpziplib,我使用Asp.net、.NET3.5、win2003、iis 6.0 我使用Oracle收集文件,将文件以SharpZipLib.BZip2压缩格式保存在Oracle表中的字段RAW中 我的应用程序是Web,我使用WCF服务获取文件的数据(字节数组)。aspx页面向用户发送文件(下载文件) 我的问题是: 我从Oracle读取数据(我调用WCF服务)。我得到字节数组(字节[]) 我尝试使用SharpZipLib.BZip2解压文件 using (MemoryStream inData = new
using (MemoryStream inData = new MemoryStream(data))
{
using (MemoryStream outData = new MemoryStream())
{
BZip2.Decompress(inData, outData); //<==================== Fails here OutOfMemoryException
return outData.ToArray();
}
}
但我从记忆中得到了同样的例外
en System.IO.MemoryStream.set_Capacity(Int32 value)
en System.IO.MemoryStream.EnsureCapacity(Int32 value)
en System.IO.MemoryStream.WriteByte(Byte value)
en Reale.Frk.Compression.BZip2.BZip2.Decompress(Stream inStream, Stream outStream)
异常跟踪堆栈
en System.IO.MemoryStream.set_Capacity(Int32 value)
en System.IO.MemoryStream.EnsureCapacity(Int32 value)
en System.IO.MemoryStream.WriteByte(Byte value)
en Reale.Frk.Compression.BZip2.BZip2.Decompress(Stream inStream, Stream outStream)
SharpZipLib.BZip2.decompresse的代码
public static void Decompress(Stream inStream, Stream outStream)
{
if ( inStream == null ) {
throw new ArgumentNullException("inStream");
}
if ( outStream == null ) {
throw new ArgumentNullException("outStream");
}
using ( outStream ) {
using ( BZip2InputStream bzis = new BZip2InputStream(inStream) ) {
int ch = bzis.ReadByte();
while (ch != -1) {
outStream.WriteByte((byte)ch);
ch = bzis.ReadByte();
}
}
}
}
任何建议、评论、示例源代码?跳过
内存流
,直接写入文件
否则,请向服务器添加更多内存
另一个为
内存流指定初始容量的选项可能是内存不足错误,因为系统上没有500 MB内存流的单个连续内存区域,但您可能有足够的非连续内存块。改用类,它可能会工作。该类可能需要一些调整(如果我没记错的话,它可能不会干净地返回最后一个块并用ASCII(0)填充它))应用程序的要求,我宁愿避免写入文件:(.添加更多内存服务器是不可能的。那你就完了。试着使用内存密集度较低的解压算法。如果添加更多内存是一个问题,我怀疑你有更大的问题……请使用其他解决方案?@Kiquenet:使用可流化压缩。GZip已经内置。