我在写一些代码来将字节数组压缩成一个较小的字节数组。然后我想解压:压缩正在工作,但解压缩不是
''' <summary>
''' Receives bytes, returns compressed bytes.
''' </summary>
Function Compress(ByRef raw() As Byte) As Byte()
Using memory As MemoryStream = New MemoryStream()
Using gzip As GZipStream = New GZipStream(memory, CompressionMode.Compress)
gzip.Write(raw, 0, raw.Length)
End Using
Return memory.ToArray()
End Using
End Function
''' <summary>
''' Receives compressed bytes, returns bytes.
''' </summary>
Function DeCompress(ByRef compress() As Byte) As Byte()
Using memory As MemoryStream = New MemoryStream()
Using gzip As GZipStream = New GZipStream(memory, CompressionMode.Decompress)
gzip.Write(compress, 0, compress.Length)
End Using
Return memory.ToArray()
End Using
End Function
(我采纳了这个here代码)
我的压缩编码的作品,但我的解压缩代码提供了以下错误:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll
Additional information: Writing to the compression stream is not supported.
我已经尝试了许多变化gzip.Read
和交换变量。 (如果我知道如何窥视VB.NET内源代码,就像我可以跟JDK也许我可以逆向工程我的方法,以解决方案,很好哦)
我怎样才能重新装备我DeCompress
功能工作意?
编辑: 我注意到我落选投票因为我没有显示.Read
方法的使用。那么我不能跟随.Read
算法,因为我的VB.NET没有.CopyTo()
函数。我不明白为什么:
当你要解压缩,你不写到流,你从它读作[GZipStream的 –
可能的复制和解压缩](http://stackoverflow.com/questions/1581694/gzipstream-and-decompression) –
我写道,我试过'gzip.Read'我不想让我的问题10页长,我的所有变化尝试..感谢您的反对票。 –