![]() |
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
(Classic ASP) 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.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% success = 0 ' This example assumes the Chilkat API has already been unlocked. ' See Global Unlock Sample for sample code. set compress = Server.CreateObject("Chilkat.Compression") ' Use the zlib algorithm (recommended for general use) compress.Algorithm = "zlib" ' ------------------------------------------------------------------ ' Compress a file ' ------------------------------------------------------------------ inputFile = "c:/temp/example.txt" compressedFile = "c:/temp/example.txt.zlib" success = compress.CompressFile(inputFile,compressedFile) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( "Compression failed:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If Response.Write "<pre>" & Server.HTMLEncode( "File compressed successfully:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( " Input: " & inputFile) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( " Compressed: " & compressedFile) & "</pre>" ' ------------------------------------------------------------------ ' Decompress the file back to its original form ' ------------------------------------------------------------------ decompressedFile = "c:/temp/example_restored.txt" success = compress.DecompressFile(compressedFile,decompressedFile) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( "Decompression failed:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If Response.Write "<pre>" & Server.HTMLEncode( "File decompressed successfully:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( " Output: " & decompressedFile) & "</pre>" ' ------------------------------------------------------------------ ' Optional: Verify file sizes (basic sanity check) ' ------------------------------------------------------------------ set fac = Server.CreateObject("Chilkat.FileAccess") originalSize = fac.FileSize(inputFile) restoredSize = fac.FileSize(decompressedFile) Response.Write "<pre>" & Server.HTMLEncode( "Original file size: " & originalSize) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "Restored file size: " & restoredSize) & "</pre>" If (originalSize = restoredSize) Then Response.Write "<pre>" & Server.HTMLEncode( "Sizes match (basic verification successful).") & "</pre>" Else Response.Write "<pre>" & Server.HTMLEncode( "Warning: File sizes differ.") & "</pre>" End If %> </body> </html> |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.