我使用 Asp.net、.net 3.5、win2003、iis 6.0。
我使用 Oracle 收集文件,将文件以 SharpZipLib.BZip2 压缩格式保存在 Oracle 表的 RAW 字段中。
我的应用程序是 Web,我使用 WCF 服务获取文件的数据(字节数组)。aspx 页面向用户发送文件(下载文件)。
我的问题:
我从 Oracle 读取数据,(我调用 WCF 服务)。我得到字节数组(byte []),
我尝试使用 SharpZipLib.BZip2 解压缩文件
using (MemoryStream inData = new MemoryStream(data))
{
using (MemoryStream outData = new MemoryStream())
{
BZip2.Decompress(inData, outData); //<==================== Fails here OutOfMemoryException
return outData.ToArray();
}
}
错误是因为“未压缩”文件很大,非常大(> 500 MB)!!!
压缩文件:4MB
未压缩文件:> 500 MB
我做这样的测试:
BufferedStream bufin = new BufferedStream(instream);
using (MemoryStream outData = new MemoryStream())
{
BZip2.Decompress(bufin, outData);
return outData.ToArray();
}
但我得到了同样的 OutOfMemoryException
跟踪异常堆栈
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.Decompress 的代码
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();
}
}
}
}
任何建议、意见、示例源代码?