Results 1 to 2 of 2

Thread: IO.Compression.DeflateStream Error

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    IO.Compression.DeflateStream Error

    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
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: IO.Compression.DeflateStream Error

    Their compression example leaves a lot to be desired. I'm in the process of switching over to the J# ZIP implementation that somebody posted in the codebank here. A lot less code and it works a lot faster and better even if it means distributing an extra install package.

    The biggest problem I had with their code example was that it played fast and loose with type conversion (Option Strict was not used) and in closing and properly disposing of streams. It also didn't get the filenames correct if there were multiple periods in the name and used questionable string concatenation methods. I went back through a lot of the code fixed this and, as I recall, this took care of a lot of the errors I had with it. I'm still wasn't that that happy with it so that's why I've moved away from it.

    If you're early on in the project, go to the J# ZIP solution if you can. Otherwise, I'd say turn on Option Strict, go through the code and fix that, then go through the code and make sure all streams are disposed of properly and that strings are being handled right. If you do this it should work, I got it to, but, as I said, I'm not that comfortable with the result.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width