使用zlib.net在vb.net上压缩字节后,具有相同长度的2个文件是否正常?
这是我使用zlib.net引用的压缩模块,2个文件是相同的,有juste小于100个字节使它们之间有区别
Imports System.IO
Imports zlib
Module zlib_compression
Public Sub CopyStream(ByRef input As System.IO.Stream, ByRef output As System.IO.Stream)
Dim num1 As Integer
Dim buffer1 As Byte() = New Byte(2000 - 1) {}
num1 = input.Read(buffer1, 0, 2000)
Do While (num1 > 0)
output.Write(buffer1, 0, num1)
num1 = input.Read(buffer1, 0, 2000)
Loop
output.Flush()
End Sub
Public Function Compress(ByVal InputBytes As Byte()) As Byte()
Using output As New MemoryStream
Dim outZStream As Stream = New ZOutputStream(output, zlib.zlibConst.Z_BEST_SPEED)
Using input As Stream = New MemoryStream(InputBytes)
CopyStream(input, outZStream)
outZStream.Close() 'do not remove
Return output.ToArray()
End Using
End Using
End Function
Public Function Decompress(ByVal InputBytes As Byte()) As Byte()
Using output As New MemoryStream
Using outZStream As Stream = New ZOutputStream(output)
Using input As Stream = New MemoryStream(InputBytes)
CopyStream(input, outZStream)
Return output.ToArray()
End Using
End Using
End Using
End Function
End Module
答案 0 :(得分:1)
当然,是的。事实上它必然是真的。不可能将所有相同长度的文件无损压缩到较小的大小,因为较小的大小中没有足够的位来标识所有原始文件。如果有些是压缩的,那么必须扩展一些。