ExtensionMethod.NET Home of 828 C#, Visual Basic, F# and Javascript extension methods


Descompactação de string


<Extension()> _
Public Function UnZip(compressedText As String) As String
    Dim gzBuffer As Byte() = Convert.FromBase64String(compressedText)
    Using ms As New MemoryStream()
        Dim msgLength As Integer = BitConverter.ToInt32(gzBuffer, 0)
        ms.Write(gzBuffer, 4, gzBuffer.Length - 4)

        Dim buffer As Byte() = New Byte(msgLength - 1) {}

        ms.Position = 0
        Using zipStream As New System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress)
            zipStream.Read(buffer, 0, buffer.Length)
        End Using

        Return System.Text.Encoding.Unicode.GetString(buffer, 0, buffer.Length)
    End Using
End Function


Dim str As String =  Base64Compressed.UnZip

Author: Alex Martins

Submitted on: 23 aug 2017

Language: VB

Type: String

Views: 1932