Ok, so here is my problem. I am trying to use DeflateStream to decompress a packet. I found an example of how to do this on the msdn site, however every time I run it I get the error "Block length does not match with its complement."
I have searched a ton on this error and found a whole lot of people with the problem and none with a solution. Below is the code I am using to Deflate the packet. Any help would be appreciated.
Code:Public Shared Function ReadAllBytesFromStream(ByVal stream As Stream, ByVal buffer() As Byte) As Byte() ' Use this method is used to read all bytes from a stream. Dim offset As Integer = 0 Dim totalCount As Integer = 0 While True 'This is the line that errors Dim bytesRead As Integer = stream.Read(buffer, offset, 100) If bytesRead = 0 Then Exit While End If offset += bytesRead totalCount += bytesRead End While Return buffer End Function Public Shared Function DeflateCompressDecompress(ByVal Data As Byte()) As Byte() Try ' Open the file as a FileStream object. Dim ms As New MemoryStream(Data) ms.Position = 0 Dim zipStream As New DeflateStream(ms, CompressionMode.Decompress) Dim decompressedBuffer(Data.Length + 100) As Byte ' Use the ReadAllBytesFromStream to read the stream. Dim returnData As Byte() = DeflateTest.ReadAllBytesFromStream(zipStream, decompressedBuffer) zipStream.Close() Return returnData Catch e As Exception Return Nothing End Try End Function






Reply With Quote