C# Streaming Decompression Example (from System.IO.Stream –> System.IO.Stream)

// Streaming decompression from System.IO.Stream --> System.IO.Stream

// In this example, the source and sink streams are files.
// However, they can be any type of System.IO.Stream, such as a System.Net.Sockets.NetworkStream
System.IO.FileStream fsSource = File.OpenRead("qa_data/image.compressed");
Chilkat.StreamConnector scSource = new Chilkat.StreamConnector();

System.IO.FileStream fsSink = File.OpenWrite("qa_data/image.bmp");
Chilkat.StreamConnector scSink = new Chilkat.StreamConnector();

Chilkat.Compression compress = new Chilkat.Compression();
compress.Algorithm = "deflate";

// Create a Chilkat.Stream object, and set the source/sink to the System.IO.Stream objects.
Chilkat.Stream stream = new Chilkat.Stream();
scSource.SetAsSource(fsSource, stream);
scSink.SetAsSink(fsSink, stream);

// Do the streaming decompress -- reading from fsSource and writing to fsSink
bool success = compress.DecompressStream(stream);

C++ String Compression: PPMD, Deflate, BZip2, LZW

This C++ example demonstrates string compression using four different compression algorithms: PPMD, Deflate, BZip2, and LZW.

void TestCompression(const char *algorithm)
    {
    CkCompression comp;

    comp.put_Algorithm(algorithm);
    printf ("algorithm: %s\n",algorithm);

    CkByteData compressedData;
    comp.CompressString("abc abc abc abc abc abc abc abc abc abc abc 123 123 abc 123",compressedData);

    // Get the compressed data:
    const unsigned char *pCompressedData = compressedData.getBytes();
    unsigned long numBytes = compressedData.getSize();
    printf("numBytes = %d\n",numBytes);

    // Imagine you've sent the compressed data over a socket connection to some receiver...


    // Decompress:
    CkByteData compressedData2;
    compressedData2.append(pCompressedData,numBytes);
    printf("%s\n",comp.decompressString(compressedData2));
    printf("----\n");
    }

void CompressionExample(void)
    {
    CkCompression comp;
    comp.UnlockComponent("30-day trial");

    TestCompression("deflate");
    TestCompression("ppmd");
    TestCompression("bzip2");
    TestCompression("lzw");

    }

The output is as follows:

algorithm: deflate
numBytes = 15
abc abc abc abc abc abc abc abc abc abc abc 123 123 abc 123
----
algorithm: ppmd
numBytes = 18
abc abc abc abc abc abc abc abc abc abc abc 123 123 abc 123
----
algorithm: bzip2
numBytes = 54
abc abc abc abc abc abc abc abc abc abc abc 123 123 abc 123
----
algorithm: lzw
numBytes = 30
abc abc abc abc abc abc abc abc abc abc abc 123 123 abc 123
----

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