Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Compress Text Feed to BinaryThis example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed binary data. The purpose is to demonstrate the BeginCompressString, MoreCompressString, and EndCompressString methods.
integer li_rc integer li_Success oleobject loo_CompressedData oleobject loo_Compress oleobject loo_SbIndex integer i string ls_OriginalText // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_CompressedData = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_CompressedData.ConnectToNewObject("Chilkat.BinData") if li_rc < 0 then destroy loo_CompressedData MessageBox("Error","Connecting to COM object failed") return end if loo_Compress = create oleobject // Use "Chilkat_9_5_0.Compression" for versions of Chilkat < 10.0.0 li_rc = loo_Compress.ConnectToNewObject("Chilkat.Compression") loo_Compress.Algorithm = "deflate" loo_Compress.Charset = "utf-8" loo_SbIndex = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbIndex.ConnectToNewObject("Chilkat.StringBuilder") for i = 0 to 24 // Note: It is possible (and normal) for a BeginCompress* or MoreCompress* method to return // an empty string (or 0 bytes). When this happens, the input data is not lost. It will be flushed // in a subsequent call. loo_SbIndex.Clear() loo_SbIndex.AppendInt(i) if i = 0 then loo_CompressedBytes = loo_Compress.BeginCompressString(loo_SbIndex.GetAsString()) else loo_CompressedBytes = loo_Compress.MoreCompressString(loo_SbIndex.GetAsString()) end if loo_CompressedData.AppendBinary(loo_CompressedBytes) loo_CompressedBytes = loo_Compress.MoreCompressString(": This is a line of data to be compressed...~r~n") loo_CompressedData.AppendBinary(loo_CompressedBytes) next // Flush any remaining output. loo_CompressedBytes = loo_Compress.EndCompressString() loo_CompressedData.AppendBinary(loo_CompressedBytes) // Show the compressed data in hex format: Write-Debug "The hex encoded compressed text:" Write-Debug loo_CompressedData.GetEncoded("hex") // Now decompress in one call: loo_CompressedBytes = loo_CompressedData.GetBinary() ls_OriginalText = loo_Compress.DecompressString(loo_CompressedBytes) Write-Debug ls_OriginalText destroy loo_CompressedData destroy loo_Compress destroy loo_SbIndex |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.