Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Tcl Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Tcl) Compress Bytes to Base64 (or any other encoding)

Compresses bytes to base64 or any other encoding. Also decompress to return the original.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

# First create some binary data to compress.
set binData [new_CkBinData]

for {set i 1} {$i <= 16} {incr i} {
    [CkBinData_AppendEncoded $binData "000102030405060708090A0B0C0D0E0F" "hex"]
}

set compress [new_CkCompression]

CkCompression_put_Algorithm $compress "deflate"
CkCompression_put_EncodingMode $compress "base64"

set uncompressedBytes [new_CkByteData]

set success [CkBinData_GetBinary $binData $uncompressedBytes]

# Compress and return the compressed bytes in base64 format.
set compressedBase64 [CkCompression_compressBytesENC $compress $uncompressedBytes]
puts "compressed and base64 encoded: $compressedBase64"

# Compress and return in hex format:
CkCompression_put_EncodingMode $compress "hex"
set compressedHex [CkCompression_compressBytesENC $compress $uncompressedBytes]
puts "compressed and hex encoded: $compressedHex"

# Now decompress..
set binData2 [new_CkBinData]

# Decompress the base64..
CkCompression_put_EncodingMode $compress "base64"
set success [CkCompression_DecompressBytesENC $compress $compressedBase64 $uncompressedBytes]
CkBinData_AppendBinary $binData2 $uncompressedBytes
# Show the uncompressed bytes in hex format:
puts [CkBinData_getEncoded $binData2 hex]
puts "--"

# Decompress the hex..
CkCompression_put_EncodingMode $compress "hex"
set success [CkCompression_DecompressBytesENC $compress $compressedHex $uncompressedBytes]
CkBinData_Clear $binData2
CkBinData_AppendBinary $binData2 $uncompressedBytes
# Show the uncompressed bytes in hex format:
puts [CkBinData_getEncoded $binData2 hex]
puts "--"

delete_CkBinData $binData
delete_CkCompression $compress
delete_CkByteData $uncompressedBytes
delete_CkBinData $binData2

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.