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) Decompress Large Text File in Blocks

Decompresses a large text file in blocks, and compares the restored (decompressed) file with the original to make sure it's correct.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

# First, let's compress a text file.
# We'll then decompress in blocks, and compare the decompressed with the original file.

# Compress a text file:
set compress [new_CkCompression]

CkCompression_put_Algorithm $compress "deflate"

set success [CkCompression_CompressFile $compress "qa_data/hamlet.xml" "qa_data/hamlet_compressed.dat"]
if {[expr $success != 1]} then {
    puts [CkCompression_lastErrorText $compress]
    delete_CkCompression $compress
    exit
}

set fac [new_CkFileAccess]

# Examine the uncompressed and compressed sizes:
set originalPath "qa_data/hamlet.xml"
puts "uncompressed size: [CkFileAccess_FileSize $fac $originalPath]"
puts "compressed size: [CkFileAccess_FileSize $fac qa_data/hamlet_compressed.dat]"

# Decompress in blocks..
set facSrc [new_CkFileAccess]

set facDest [new_CkFileAccess]

CkFileAccess_OpenForRead $facSrc "qa_data/hamlet_compressed.dat"

# If we compress in 32K chunks, find out how many blocks there will be.
set blockSize 32768
set numBlocks [CkFileAccess_GetNumBlocks $facSrc $blockSize]

# Open an output file for the decompressed data.
set restoredPath "qa_output/hamlet_restored.xml"
set success [CkFileAccess_OpenForWrite $facDest $restoredPath]
if {[expr $success != 1]} then {
    puts [CkFileAccess_lastErrorText $facDest]
    delete_CkCompression $compress
    delete_CkFileAccess $fac
    delete_CkFileAccess $facSrc
    delete_CkFileAccess $facDest
    exit
}

set compressedBytes [new_CkByteData]

set i 0
while {[expr $i < $numBlocks]} {
    set success [CkFileAccess_ReadBlock $facSrc $i $blockSize $compressedBytes]
    if {[expr $i == 0]} then {
        set decompressedStr [CkCompression_beginDecompressString $compress $compressedBytes]
    }     else {
        set decompressedStr [CkCompression_moreDecompressString $compress $compressedBytes]
    }

    [CkFileAccess_AppendText $facDest $decompressedStr "utf-8"]

    set i [expr $i + 1]
}

# At the very end, flush any remaining content, if any.
set decompressedStr [CkCompression_endDecompressString $compress]
CkFileAccess_AppendText $facDest $decompressedStr "utf-8"

CkFileAccess_FileClose $facSrc
CkFileAccess_FileClose $facDest

# Examine the size of the restored file.
puts "restored size: [CkFileAccess_FileSize $fac $restoredPath]"

# Compare the contents of the original with the restored.
set bEqualContents [CkFileAccess_FileContentsEqual $fac $restoredPath $originalPath]
puts "Contents Equal: $bEqualContents"

delete_CkCompression $compress
delete_CkFileAccess $fac
delete_CkFileAccess $facSrc
delete_CkFileAccess $facDest
delete_CkByteData $compressedBytes

 

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