![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) Chunked Compression Using CompressBd2 with FirstChunk and LastChunkSee more Compression ExamplesThis example demonstrates how to compress data in multiple segments using theCompressBd2 method together with the FirstChunk and LastChunk properties. Instead of compressing all data in a single call, the input is divided into smaller chunks and processed sequentially, which is useful when handling streaming data or large inputs.
The example shows how to correctly mark the first, middle, and final chunks so that the compression stream is properly initialized and finalized. The compressed output is accumulated in a separate This approach is ideal for scenarios where data is received incrementally, such as reading from a network stream, processing large files in parts, or handling real-time data feeds.
LOCAL lnSuccess LOCAL loCompress LOCAL loBdOut LOCAL lcPart1 LOCAL lcPart2 LOCAL lcPart3 LOCAL loBdIn LOCAL lcCompressedBase64 LOCAL loBdDecompressed LOCAL lcResultText lnSuccess = 0 * This example assumes the Chilkat API has already been unlocked. * See Global Unlock Sample for sample code. loCompress = CreateObject('Chilkat.Compression') loCompress.Algorithm = "zlib" * This will accumulate the compressed output. loBdOut = CreateObject('Chilkat.BinData') * ------------------------------------------------------------------ * Simulate input arriving in chunks. * ------------------------------------------------------------------ lcPart1 = "The quick brown fox " lcPart2 = "jumps over the lazy dog. " lcPart3 = "This text is split into chunks." * ------------------------------------------------------------------ * Compress the first chunk * ------------------------------------------------------------------ loCompress.FirstChunk = 1 loCompress.LastChunk = 0 loBdIn = CreateObject('Chilkat.BinData') loBdIn.AppendString(lcPart1,"utf-8") lnSuccess = loCompress.CompressBd2(loBdIn,loBdOut) IF (lnSuccess = 0) THEN ? loCompress.LastErrorText RELEASE loCompress RELEASE loBdOut RELEASE loBdIn CANCEL ENDIF * ------------------------------------------------------------------ * Compress a middle chunk * ------------------------------------------------------------------ loCompress.FirstChunk = 0 loCompress.LastChunk = 0 loBdIn.Clear() loBdIn.AppendString(lcPart2,"utf-8") lnSuccess = loCompress.CompressBd2(loBdIn,loBdOut) IF (lnSuccess = 0) THEN ? loCompress.LastErrorText RELEASE loCompress RELEASE loBdOut RELEASE loBdIn CANCEL ENDIF * ------------------------------------------------------------------ * Compress the final chunk * ------------------------------------------------------------------ loCompress.FirstChunk = 0 loCompress.LastChunk = 1 loBdIn.Clear() loBdIn.AppendString(lcPart3,"utf-8") lnSuccess = loCompress.CompressBd2(loBdIn,loBdOut) IF (lnSuccess = 0) THEN ? loCompress.LastErrorText RELEASE loCompress RELEASE loBdOut RELEASE loBdIn CANCEL ENDIF * Get the final compressed result as base64 for display lcCompressedBase64 = loBdOut.GetEncoded("base64") ? "Compressed data (base64):" ? lcCompressedBase64 * ------------------------------------------------------------------ * Decompress to verify correctness * ------------------------------------------------------------------ loBdDecompressed = CreateObject('Chilkat.BinData') loCompress.FirstChunk = 1 loCompress.LastChunk = 1 lnSuccess = loCompress.DecompressBd2(loBdOut,loBdDecompressed) IF (lnSuccess = 0) THEN ? loCompress.LastErrorText RELEASE loCompress RELEASE loBdOut RELEASE loBdIn RELEASE loBdDecompressed CANCEL ENDIF * Convert decompressed bytes back to a string lcResultText = loBdDecompressed.GetString("utf-8") ? "Decompressed text:" ? lcResultText RELEASE loCompress RELEASE loBdOut RELEASE loBdIn RELEASE loBdDecompressed |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.