Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Unzip Binary File to StreamDemonstrates how to unzip a large binary file to a stream to allow the application to process the uncompressed bytes chunk by chunk. Note: This example requires Chilkat v9.5.0.67 or greater.
IncludeFile "CkBinData.pb" IncludeFile "CkFileAccess.pb" IncludeFile "CkZip.pb" IncludeFile "CkStream.pb" IncludeFile "CkTask.pb" IncludeFile "CkZipEntry.pb" Procedure ChilkatExample() ; This requires the Chilkat Zip API to have been previously unlocked. ; See Unlock Chilkat Zip for sample code. zip.i = CkZip::ckCreate() If zip.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; First open a .zip. success.i = CkZip::ckOpenZip(zip,"qa_data/zips/big.zip") If success <> 1 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Get the entry to be unzipped to a stream.. entry.i = CkZip::ckGetEntryByIndex(zip,0) If CkZip::ckLastMethodSuccess(zip) <> 1 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf dataStream.i = CkStream::ckCreate() If dataStream.i = 0 Debug "Failed to create object." ProcedureReturn EndIf unzipTask.i = CkZipEntry::ckUnzipToStreamAsync(entry,dataStream) If CkZipEntry::ckLastMethodSuccess(entry) <> 1 Debug CkZipEntry::ckLastErrorText(entry) CkZipEntry::ckDispose(entry) CkZip::ckDispose(zip) CkStream::ckDispose(dataStream) ProcedureReturn EndIf ; Start the background unzip thread. CkTask::ckRun(unzipTask) ; We'll read the uncompressed data chunk-by-chunk and write to an output file. fac.i = CkFileAccess::ckCreate() If fac.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkFileAccess::ckOpenForWrite(fac,"qa_output/out.dat") If success <> 1 Debug CkFileAccess::ckLastErrorText(fac) CkZipEntry::ckDispose(entry) CkZip::ckDispose(zip) CkStream::ckDispose(dataStream) CkFileAccess::ckDispose(fac) ProcedureReturn EndIf ; Read the stream. (this is reading the unzipped file data) bd.i = CkBinData::ckCreate() If bd.i = 0 Debug "Failed to create object." ProcedureReturn EndIf While CkStream::ckEndOfStream(dataStream) <> 1 ; Get the next chunk of decompressed bytes. CkStream::ckReadBd(dataStream,bd) ; Do something with it.. ; In this simple example, we'll just write to the file. CkFileAccess::ckFileWriteBd(fac,bd,0,0) ; Clear for the next read. CkBinData::ckClear(bd) Wend CkFileAccess::ckFileClose(fac) CkZipEntry::ckDispose(entry) CkTask::ckDispose(unzipTask) Debug "Success." CkZip::ckDispose(zip) CkStream::ckDispose(dataStream) CkFileAccess::ckDispose(fac) CkBinData::ckDispose(bd) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.