Hi,
I am inserting BLOBS into my database(basically rich text), to enhance the network speed, I am compressing them before insert. However when I decompress it, I am not getting the content... see the following logic....

I get a "file format invalid" error

Code:
Friend Function CompressBytes(ByVal rtfString As String) As Byte()
        Try
            Dim Compressor As System.IO.Compression.GZipStream
            Dim EC As New System.Text.UTF8Encoding
            Dim bytes() As Byte=EC.GetBytes(rtfString)
            Dim ms As New System.IO.MemoryStream
            ms.Write(bytes, 0, bytes.Length)
            ms.Position = 0
            Compressor = New System.IO.Compression.GZipStream(ms, IO.Compression.CompressionMode.Compress, True)
            Compressor.Write(bytes, 0, bytes.Length)
            
            ms.ToArray()

        Catch ex As Exception
            DE(ex)
        End Try
    End Function

Friend Function DecompressBytes(ByVal bytes() As Byte) As String
        Try
            Dim ms As New System.IO.MemoryStream
            Dim EC As New System.Text.UTF8Encoding
             ms.Write(bytes, 0, bytes.Length)
            ms.Position = 0
            Dim DeCompressor As IO.Compression.GZipStream = New System.IO.Compression.GZipStream(ms, IO.Compression.CompressionMode.Decompress, True)
            Dim offset As Integer = 0
            Dim totalbytes As Integer = 0
            Dim smallBuffer(100) As Byte
            Dim bytesread As Integer = 0
            bytesread = DeCompressor.Read(smallBuffer, 0, 100)
            ms.Position = 0
            While (True)
                bytesread = DeCompressor.Read(smallBuffer, 0, 100)
                If (bytesread = 0) Then
                    Exit While
                End If
                offset += bytesread
                totalbytes += bytesread
            End While
            Dim byt(totalbytes) As Byte
            ms.Position = 0
            DeCompressor.Read(byt, 0, totalbytes)
            ms.Close()
            ms.Dispose()
            Return EC.GetString(byt)
        Catch ex As Exception
            DE(ex)
        End Try
    End Function
Thanks
Vijay S