次のコードを使用して、VB.Net でファイルの圧縮を開始しました。Fx 2.0 をターゲットにしているため、このStream.CopyTo
メソッドは使用できません。
Normal
ただし、私のコードは、7-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
複数のバッファ サイズを試してみましたが、同様の圧縮時間とまったく同じ圧縮率が得られます。