Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(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-2024 Chilkat Software, Inc. All Rights Reserved.