![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java 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
(Go) Compress Text Feed to BinaryThis example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed binary data. Note: This example requires Chilkat v11.0.0 or greater.
success := false // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. bdCompressed := BinData_Ref.html">chilkat.NewBinData() compress := Compression_Ref.html">chilkat.NewCompression() compress.SetAlgorithm("deflate") compress.SetCharset("utf-8") sbUncompressedChunk := StringBuilder_Ref.html">chilkat.NewStringBuilder() compress.SetFirstChunk(true) compress.SetLastChunk(false) var i int for i = 0; i <= 24; i++ { if i == 24 { compress.SetLastChunk(true) } sbUncompressedChunk.Clear() sbUncompressedChunk.AppendInt(i) sbUncompressedChunk.Append(": This is a line of data to be compressed...\r\n") compress.CompressSb(sbUncompressedChunk,bdCompressed) compress.SetFirstChunk(false) } // Show the compressed data in hex format: fmt.Println("The hex encoded compressed text:") fmt.Println(*bdCompressed.GetEncoded("hex")) // Now decompress in one call. It is important to set both FirstChunk and LastChunk = true bdDecompressed := BinData_Ref.html">chilkat.NewBinData() compress.SetFirstChunk(true) compress.SetLastChunk(true) success = compress.DecompressBd2(bdCompressed,bdDecompressed) if success == false { fmt.Println(compress.LastErrorText()) bdCompressed.DisposeBinData() compress.DisposeCompression() sbUncompressedChunk.DisposeStringBuilder() bdDecompressed.DisposeBinData() return } originalText := bdDecompressed.GetString("utf-8") fmt.Println(*originalText) bdCompressed.DisposeBinData() compress.DisposeCompression() sbUncompressedChunk.DisposeStringBuilder() bdDecompressed.DisposeBinData() |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.