VB.NET Compress String to Byte Array
Demonstrates how to use Chilkat.Compression to compress a string to a byte array:
Private Sub CompressStringToBytes()
Dim compress As New Chilkat.Compression()
' Any string argument automatically begins a 30-day trial.
Dim success As Boolean
success = compress.UnlockComponent("30-day trial")
If (success <> True) Then
MsgBox("Compression component unlock failed")
Exit Sub
End If
' Use the "deflate" algorithm, which is the algorithm used
' for .zip. Other algorithms are "lzw", "bzip2", and "ppmd"
compress.Algorithm = "deflate"
Dim strData As String
' Create a string to compress:
strData = "hellohellohellohellohellohellohellohellohellohello"
MessageBox.Show("Uncompressed size: " & strData.Length.ToString())
' Tell the component to convert to
' ansi (1-byte/char) prior to compression:
compress.Charset = "ansi"
Dim compressedData As Byte()
compressedData = compress.CompressString(strData)
MessageBox.Show("Compressed size: " & compressedData.Length.ToString())
' Decompress:
Dim origStr As String
origStr = compress.DecompressString(compressedData)
MessageBox.Show(origStr)
End Sub
admin
0
Tags :