![]() |
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
(VBScript) Compress Text from StringBuilder to Gzip (BinData Output)See more Gzip ExamplesThis example demonstrates how to use the The text is first converted to its byte representation using the specified character set (in this case, UTF-8). These bytes are then compressed, and the resulting Gzip data is written to a This approach is useful when working with dynamically generated text that you want to compress without first writing it to a file. The example also shows how the compressed data can optionally be saved to a
Dim fso, outFile Set fso = CreateObject("Scripting.FileSystemObject") 'Create a Unicode (utf-16) output text file. Set outFile = fso.CreateTextFile("output.txt", True, True) success = 0 ' This example demonstrates how to compress text contained in a StringBuilder ' into Gzip format, storing the compressed result in a BinData object. set gzip = CreateObject("Chilkat.Gzip") set sb = CreateObject("Chilkat.StringBuilder") set bd = CreateObject("Chilkat.BinData") ' Add some text to the StringBuilder: success = sb.Append("The quick brown fox jumps over the lazy dog.") ' Compress the text using UTF-8 encoding: success = gzip.CompressSb(sb,"utf-8",bd) If (success = 0) Then outFile.WriteLine(gzip.LastErrorText) WScript.Quit End If ' The BinData now contains the Gzip-compressed bytes. outFile.WriteLine("Compression successful.") outFile.WriteLine("Compressed size (bytes): " & bd.NumBytes) ' (Optional) Save to a .gz file: success = bd.WriteFile("text.gz") If (success = 0) Then outFile.WriteLine(bd.LastErrorText) WScript.Quit End If outFile.WriteLine("Gzip file written to text.gz") outFile.Close |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.