是否与IO.Com pression有问题吗? [英] Is there a problem with IO.Compression?

查看:140
本文介绍了是否与IO.Com pression有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在VB.Net COM pressing文件,使用下面的code。因为我针对Fx的2.0,我不能使用 Stream.CopyTo 方法。

I've just started compressing file in VB.Net, using the following code. Since I'm targeting Fx 2.0, I can't use the Stream.CopyTo method.

我的code,但是,给人非常不好的结果相比,GZIP 正常 COM pression在7-ZIP轮廓。例如,我的code COM pressed一个630MB的前景存档740MB,而7-ZIP使得它490MB。

My code, however, gives extremely poor results compared to the gzip Normal compression profile in 7-zip. For example, my code compressed a 630MB outlook archive to 740MB, and 7-zip makes it 490MB.

下面是code。是否有一个赤裸裸的错误(或多个?)

Here is the code. Is there a blatant mistake (or many?)

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

我已经试过多个缓冲区大小,但我得到类似COM pression倍,并具有完全相同的COM pression比。

I've tried with multiple buffer sizes, but I get similar compression times, and exactly the same compression ratio.

推荐答案

修改,或者实际上改写:它看起来像BCL codeRS决定的phone~~V它

EDIT, or actually rewrite: It looks like the BCL coders decided to phone it in.

System.dll中 2.0版本使用的静态定义,很难codeD哈夫曼树以ASCII纯文本进行了优化,而不是自适应生成哈夫曼树的其他实现做。它也不支持存储块的优化(这是的GZip /放气标准如何避免失控扩展)。其结果是,通过其执行以外明文运行的任何类型的文件都将导致比输入大得多文件,微软<一href="http://connect.microsoft.com/VisualStudio/feedback/details/93636/gzipstream-deflatestream-increase-file-size-on-com$p$pssion">claims这是由设计!

The implementation in System.dll version 2.0 uses statically defined, hardcoded Huffman trees optimized for plain ASCII text, rather than adaptively generating the Huffman trees as other implementations do. It also doesn't support stored-block optimization (which is how standard GZip/Deflate avoid runaway expansion). As a result, running any sort of file through their implementation other than plain text will result in a much larger file than the input, and Microsoft claims this is by design!

保存自己有些疼痛,抢第三方实施

Save yourself some pain, grab a third party implementation.

这篇关于是否与IO.Com pression有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆