![]() |
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
(AutoIt) Decompress Large Text File in BlocksDecompresses a large text file in blocks, and compares the restored (decompressed) file with the original to make sure it's correct.
; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; First, let's compress a text file. ; We'll then decompress in blocks, and compare the decompressed with the original file. ; Compress a text file: $oCompress = ObjCreate("Chilkat_9_5_0.Compression") $oCompress.Algorithm = "deflate" Local $bSuccess = $oCompress.CompressFile("qa_data/hamlet.xml","qa_data/hamlet_compressed.dat") If ($bSuccess <> True) Then ConsoleWrite($oCompress.LastErrorText & @CRLF) Exit EndIf $oFac = ObjCreate("Chilkat_9_5_0.FileAccess") ; Examine the uncompressed and compressed sizes: Local $sOriginalPath = "qa_data/hamlet.xml" ; Note: The FileSize method returns a signed 32-bit integer. If the file is potentially larger than 2GB, call FileSizeStr instead to return ; the size of the file as a string, then convert to an integer value. ConsoleWrite("uncompressed size: " & $oFac.FileSize($sOriginalPath) & @CRLF) ConsoleWrite("compressed size: " & $oFac.FileSize("qa_data/hamlet_compressed.dat") & @CRLF) ; Decompress in blocks.. $oFacSrc = ObjCreate("Chilkat_9_5_0.FileAccess") $oFacDest = ObjCreate("Chilkat_9_5_0.FileAccess") $oFacSrc.OpenForRead("qa_data/hamlet_compressed.dat") ; If we compress in 32K chunks, find out how many blocks there will be. Local $iBlockSize = 32768 Local $iNumBlocks = $oFacSrc.GetNumBlocks($iBlockSize) ; Open an output file for the decompressed data. Local $sRestoredPath = "qa_output/hamlet_restored.xml" $bSuccess = $oFacDest.OpenForWrite($sRestoredPath) If ($bSuccess <> True) Then ConsoleWrite($oFacDest.LastErrorText & @CRLF) Exit EndIf Local $sDecompressedStr Local $oCompressedBytes Local $i = 0 While $i < $iNumBlocks $oCompressedBytes = $oFacSrc.ReadBlock($i,$iBlockSize) If ($i = 0) Then $sDecompressedStr = $oCompress.BeginDecompressString($oCompressedBytes) Else $sDecompressedStr = $oCompress.MoreDecompressString($oCompressedBytes) EndIf $oFacDest.AppendText($sDecompressedStr,"utf-8") $i = $i + 1 Wend ; At the very end, flush any remaining content, if any. $sDecompressedStr = $oCompress.EndDecompressString() $oFacDest.AppendText($sDecompressedStr,"utf-8") $oFacSrc.FileClose $oFacDest.FileClose ; Examine the size of the restored file. ConsoleWrite("restored size: " & $oFac.FileSize($sRestoredPath) & @CRLF) ; Compare the contents of the original with the restored. Local $bEqualContents = $oFac.FileContentsEqual($sRestoredPath,$sOriginalPath) ConsoleWrite("Contents Equal: " & $bEqualContents & @CRLF) |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.