我使用下面的代码来压缩文件,它们一直在增长而不是缩小。我压缩了一个 4 kb 的文件,它变成了 6 个。由于压缩开销,这对于一个小文件是可以理解的。我尝试了一个 400 mb 的文件,压缩后它变成了 628 mb。怎么了?查看代码。(.net 2.0)
Public Sub Compress(ByVal infile As String, ByVal outfile As String)
Dim sourceFile As FileStream = File.OpenRead(inFile)
Dim destFile As FileStream = File.Create(outfile)
Dim compStream As New GZipStream(destFile, CompressionMode.Compress)
Dim myByte As Integer = sourceFile.ReadByte()
While myByte <> -1
compStream.WriteByte(CType(myByte, Byte))
myByte = sourceFile.ReadByte()
End While
sourceFile.Close()
destFile.Close()
End Sub