![]() |
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) Stream a Large ZIP Entry While Uncompressing Using ZipEntry.UnzipToStreamAsyncSee more Zip Examples This example demonstrates how to use The example is especially useful for large ZIP entries because the entire uncompressed file does not need to be held in memory at once. Instead, the uncompressed data is processed incrementally in chunks as it becomes available. The example performs the following steps:
This approach is useful when:
The example demonstrates a producer/consumer pattern where:
The uncompressed bytes are written incrementally to: Note: The standard Therefore, it is not necessary to use a more complex streaming approach such as this example merely to efficiently unzip large files to disk. The purpose of this example is instead to demonstrate how an application can directly access and process the uncompressed data incrementally in chunks as the unzip operation is occurring. This technique is ideal when the application needs to inspect, analyze, transform, transmit, or otherwise process the uncompressed bytes while they are being produced. Note: This example requires Chilkat v11.0.0 or greater.
LOCAL lnSuccess LOCAL loZip LOCAL loEntry LOCAL loDataStream LOCAL loUnzipTask LOCAL loFac LOCAL loBd lnSuccess = 0 lnSuccess = 0 loZip = CreateObject('Chilkat.Zip') * Open an existing ZIP archive. lnSuccess = loZip.OpenZip("qa_data/zips/big.zip") IF (lnSuccess = 0) THEN ? loZip.LastErrorText RELEASE loZip CANCEL ENDIF * Get the ZIP entry to be unzipped. * * This example uses the first entry in the ZIP archive. * The entry may contain a large file, so we will unzip it * to a stream instead of loading the entire file into memory. loEntry = CreateObject('Chilkat.ZipEntry') lnSuccess = loZip.EntryAt(0,loEntry) IF (lnSuccess = 0) THEN ? loZip.LastErrorText RELEASE loZip RELEASE loEntry CANCEL ENDIF * Create the stream that will receive the uncompressed data. loDataStream = CreateObject('Chilkat.Stream') * Start an asynchronous unzip operation. * * UnzipToStreamAsync writes the uncompressed entry data to dataStream * from a background thread. The foreground thread can read from the * stream as data becomes available. loUnzipTask = loEntry.UnzipToStreamAsync(loDataStream) IF (loEntry.LastMethodSuccess = 0) THEN ? loEntry.LastErrorText RELEASE loZip RELEASE loEntry RELEASE loDataStream CANCEL ENDIF * Start the background unzip thread. loUnzipTask.Run() * Open the output file that will receive the uncompressed data. loFac = CreateObject('Chilkat.FileAccess') lnSuccess = loFac.OpenForWrite("c:/temp/qa_output/out.dat") IF (lnSuccess = 0) THEN ? loFac.LastErrorText RELEASE loZip RELEASE loEntry RELEASE loDataStream RELEASE loFac CANCEL ENDIF * Read the uncompressed data from the stream in chunks. * * This avoids holding the entire uncompressed file in memory. * Each chunk is written immediately to the output file. loBd = CreateObject('Chilkat.BinData') DO WHILE (loDataStream.EndOfStream <> 1) * Read the next available chunk of uncompressed bytes. loDataStream.ReadBd(loBd) * Write this chunk to the output file. loFac.FileWriteBd(loBd,0,0) * Clear the BinData object so it can be reused for the next chunk. loBd.Clear() ENDDO * Close the output file. loFac.FileClose() * The background unzip task has completed when the stream reaches EOF. * Delete the task object when no longer needed. RELEASE loUnzipTask * Close the ZIP archive. loZip.CloseZip() ? "Success." RELEASE loZip RELEASE loEntry RELEASE loDataStream RELEASE loFac RELEASE loBd |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.