![]() |
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) Compressing and Decompressing Files Using Streaming (CompressFile / DecompressFile)See more Compression Examples
This example demonstrates how to compress a file to a binary format and then restore it using the Both operations are performed internally in streaming mode, allowing files of any size to be processed efficiently without loading the entire file into memory. The example also includes a simple verification step by comparing file sizes to confirm that the decompressed output matches the original input.
LOCAL lnSuccess LOCAL loCompress LOCAL lcInputFile LOCAL lcCompressedFile LOCAL lcDecompressedFile LOCAL loFac LOCAL lnOriginalSize LOCAL lnRestoredSize lnSuccess = 0 * This example assumes the Chilkat API has already been unlocked. * See Global Unlock Sample for sample code. loCompress = CreateObject('Chilkat.Compression') * Use the zlib algorithm (recommended for general use) loCompress.Algorithm = "zlib" * ------------------------------------------------------------------ * Compress a file * ------------------------------------------------------------------ lcInputFile = "c:/temp/example.txt" lcCompressedFile = "c:/temp/example.txt.zlib" lnSuccess = loCompress.CompressFile(lcInputFile,lcCompressedFile) IF (lnSuccess = 0) THEN ? "Compression failed:" ? loCompress.LastErrorText RELEASE loCompress CANCEL ENDIF ? "File compressed successfully:" ? " Input: " + lcInputFile ? " Compressed: " + lcCompressedFile * ------------------------------------------------------------------ * Decompress the file back to its original form * ------------------------------------------------------------------ lcDecompressedFile = "c:/temp/example_restored.txt" lnSuccess = loCompress.DecompressFile(lcCompressedFile,lcDecompressedFile) IF (lnSuccess = 0) THEN ? "Decompression failed:" ? loCompress.LastErrorText RELEASE loCompress CANCEL ENDIF ? "File decompressed successfully:" ? " Output: " + lcDecompressedFile * ------------------------------------------------------------------ * Optional: Verify file sizes (basic sanity check) * ------------------------------------------------------------------ loFac = CreateObject('Chilkat.FileAccess') lnOriginalSize = loFac.FileSize(lcInputFile) lnRestoredSize = loFac.FileSize(lcDecompressedFile) ? "Original file size: " + STR(lnOriginalSize) ? "Restored file size: " + STR(lnRestoredSize) IF (lnOriginalSize = lnRestoredSize) THEN ? "Sizes match (basic verification successful)." ELSE ? "Warning: File sizes differ." ENDIF RELEASE loCompress RELEASE loFac |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.