[VB6 equivalent: ZLIB_Deflate]
Dim strPlain As String Dim strBack As String Dim abPlain() As Byte Dim abCompressed() As Byte Dim nUncompLen As Integer ' COMPRESSSION (deflation) ' Set the plaintext message strPlain = "hello, hello, hello. This is a 'hello world' message " & _ "for the world, repeat, for the world." ' Convert to an array of bytes abPlain = System.Text.Encoding.Default.GetBytes(strPlain) nUncompLen = abPlain.Length ' Now compress plaintext abCompressed = Zlib.Deflate(abPlain) Console.WriteLine("Compressed " & abPlain.Length & " bytes to " & abCompressed.Length) ' DECOMPRESSSION (inflation) ' Uncompress the compressed data ' Note: we must know the uncompressed length here abPlain = Zlib.Inflate(abCompressed, nUncompLen) ' Convert back to a string strBack = System.Text.Encoding.Default.GetString(abPlain) Console.WriteLine(strBack)
See Also:
Zlib.Deflate Method