我刚刚开始在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决定的