Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Unzip Binary File to Stream

Demonstrates 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoZip
    Boolean iSuccess
    Variant vEntry
    Handle hoEntry
    Variant vDataStream
    Handle hoDataStream
    Variant vUnzipTask
    Handle hoUnzipTask
    Handle hoFac
    Variant vBd
    Handle hoBd
    String sTemp1
    Boolean bTemp1

    //  This requires the Chilkat Zip API to have been previously unlocked.
    //  See Unlock Chilkat Zip for sample code.

    Get Create (RefClass(cComChilkatZip)) To hoZip
    If (Not(IsComObjectCreated(hoZip))) Begin
        Send CreateComObject of hoZip
    End

    //  First open a .zip.
    Get ComOpenZip Of hoZip "qa_data/zips/big.zip" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Get the entry to be unzipped to a stream..
    Get ComGetEntryByIndex Of hoZip 0 To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Get ComLastMethodSuccess Of hoZip To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStream)) To hoDataStream
    If (Not(IsComObjectCreated(hoDataStream))) Begin
        Send CreateComObject of hoDataStream
    End

    Get pvComObject of hoDataStream to vDataStream
    Get ComUnzipToStreamAsync Of hoEntry vDataStream To vUnzipTask
    If (IsComObject(vUnzipTask)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoUnzipTask
        Set pvComObject Of hoUnzipTask To vUnzipTask
    End
    Get ComLastMethodSuccess Of hoEntry To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoEntry To sTemp1
        Showln sTemp1
        Send Destroy of hoEntry
        Procedure_Return
    End

    //  Start the background unzip thread.
    Get ComRun Of hoUnzipTask To iSuccess

    //  We'll read the uncompressed data chunk-by-chunk and write to an output file.
    Get Create (RefClass(cComCkFileAccess)) To hoFac
    If (Not(IsComObjectCreated(hoFac))) Begin
        Send CreateComObject of hoFac
    End
    Get ComOpenForWrite Of hoFac "qa_output/out.dat" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFac To sTemp1
        Showln sTemp1
        Send Destroy of hoEntry
        Procedure_Return
    End

    //  Read the stream.  (this is reading the unzipped file data)
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    While ((ComEndOfStream(hoDataStream)) <> True)
        //  Get the next chunk of decompressed bytes.
        Get pvComObject of hoBd to vBd
        Get ComReadBd Of hoDataStream vBd To iSuccess
        //  Do something with it..
        //  In this simple example, we'll just write to the file.
        Get pvComObject of hoBd to vBd
        Get ComFileWriteBd Of hoFac vBd 0 0 To iSuccess
        //  Clear for the next read.
        Get ComClear Of hoBd To iSuccess
    Loop

    Send ComFileClose To hoFac

    Send Destroy of hoEntry
    Send Destroy of hoUnzipTask
    Showln "Success."


End_Procedure

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.