我在寫一些代碼來將字節數組壓縮成一個較小的字節數組。然後我想解壓:壓縮正在工作,但解壓縮不是
''' <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頁長,我的所有變化嘗試..感謝您的反對票。 –