Clé*_*ent 3 .net vb.net compression gzip gzipstream
我刚刚开始使用以下代码在VB.Net中压缩文件.由于我的目标是Fx 2.0,我无法使用该Stream.CopyTo方法.
但是,与Normal7-zip中的gzip 压缩配置文件相比,我的代码的结果非常差.例如,我的代码将630MB outlook存档压缩为740MB,而7-zip则为490MB.
这是代码.有一个明显的错误(或许多?)
Using Input As New IO.FileStream(SourceFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Using outFile As IO.FileStream = IO.File.Create(DestFile)
Using Compress As IO.Compression.GZipStream = New IO.Compression.GZipStream(outFile, IO.Compression.CompressionMode.Compress)
'TODO: Figure out the right buffer size.'
Dim Buffer(524228) As Byte
Dim ReadBytes As Integer = 0
While True
ReadBytes = Input.Read(Buffer, 0, Buffer.Length)
If ReadBytes <= 0 Then Exit While
Compress.Write(Buffer, 0, ReadBytes)
End While
End Using
End Using
End Using
Run Code Online (Sandbox Code Playgroud)
我已尝试使用多种缓冲区大小,但我得到了类似的压缩时间和完全相同的压缩率.
编辑,或实际重写:看起来BCL编码器决定打电话给它.
System.dll版本2.0中的实现使用针对纯ASCII文本优化的静态定义的硬编码霍夫曼树,而不是像其他实现那样自适应地生成霍夫曼树.它也不支持存储块优化(这是标准GZip/Deflate避免失控扩展的方式).因此,通过除纯文本以外的实现运行任何类型的文件将导致比输入更大的文件,并且Microsoft 声称这是设计的!
节省一些痛苦,抓住第三方实施.
| 归档时间: |
|
| 查看次数: |
1051 次 |
| 最近记录: |