C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

PPMD Streaming String Compression

Demonstrates streaming string compression using PPMD. Data may be compressed in chunks by initially calling one of the BeginCompress* methods, followed by 0 or more calls to a MoreCompress* method, and terminating with a call to an EndCompress* method.

Likewise, data may be decompressed by calling a BeginDecompress* method, followed by 0 or more MoreDecompress* calls, and ending with an EndDecompress* method call.

This example demonstrates string-to-string compression and decompression in chunks.

Download: Chilkat .NET Assemblies

Chilkat.Compression compress = new Chilkat.Compression();

//  Any string argument automatically begins a 30-day trial.
bool success;
success = compress.UnlockComponent("30-day trial");
if (success != true) {
    MessageBox.Show("Compression component unlock failed");
    return;
}

compress.Algorithm = "ppmd";
compress.Charset = "ansi";
compress.EncodingMode = "base64";

string strData;
int i;

string strCompressed;

//  Create a long string to compress.
strData = "abcdefg1122334455667788";
strData = strData + "\r\n";

//  Note: BeginCompressStringENC may return a zero-length
//  string.  This is normal if the input is buffered and no
//  compressed data is yet available.
//  However, a null reference indicates an error -- which is
//  generally only possible if the component was never unlocked.
strCompressed = compress.BeginCompressStringENC(strData);

//  Compress 100 more chunks of data.  Each call to
//  MoreCompressStringENC may or may not produce additional
//  compressed output.
for (i = 0; i <= 99; i++) {
    strData = "abcdefg1122334455667788";
    strData = strData + "\r\n";

    strCompressed = strCompressed + compress.MoreCompressStringENC(strData);
}

//  Finalize the compression with a single call to EndCompressStringENC:
strCompressed = strCompressed + compress.EndCompressStringENC();

//  Display the compressed string.
//  The result will be:
//  ec8YZ5vk9za18d0plwuV7R65em9OZge9gJXht/QAAAAAAAAAABNOZQAAKw==

textBox1.Text += strCompressed + "\r\n";

//  Decompress back to the original in a single call.
string strOriginal;
strOriginal = compress.DecompressStringENC(strCompressed);

//  Display the uncompressed original:
textBox1.Text += "--- Original ---" + "\r\n";
textBox1.Text += strOriginal + "\r\n";

//  Decompress in multiple calls.  It doesn't matter how the
//  compressed data is split -- it could be fed to the decompressor
//  one char at a time if desired.
string chunk1;
chunk1 = "ec8YZ5vk9za1";
string chunk2;
chunk2 = "8d0p";
string chunk3;
chunk3 = "lwuV7R65em9OZge9gJXht/QAAAA";
string chunk4;
chunk4 = "AAAAAABNOZQAAKw==";

strOriginal = "";
strOriginal = compress.BeginDecompressStringENC(chunk1);
strOriginal = strOriginal + compress.MoreDecompressStringENC(chunk2);
strOriginal = strOriginal + compress.MoreDecompressStringENC(chunk3);
strOriginal = strOriginal + compress.MoreDecompressStringENC(chunk4);
strOriginal = strOriginal + compress.EndDecompressStringENC();

//  Display the uncompressed original after decompressing in chunks:
textBox1.Text += "--- Original after Decompressing from Chunks ---" + "\r\n";
textBox1.Text += strOriginal + "\r\n";
 

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