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
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 One File to a Stream

Demonstrates how to unzip a particular file contained within a .zip archive to a Chilkat stream.

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 vStreamA
    Handle hoStreamA
    Variant vStreamB
    Handle hoStreamB
    Variant vUnzipTask
    Handle hoUnzipTask
    Variant vSb
    Handle hoSb
    Variant vStreamC
    Handle hoStreamC
    String s
    String sTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample 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/hamlet.zip" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoZip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Find the entry to be unzipped to a stream..
    Get ComFirstMatchingEntry Of hoZip "*hamlet.xml" 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

    // There are three ways we can unzip (inflate) to a stream.
    // 
    // 1) Set a sink file on the stream object and call UnzipToStream synchronously.
    //    This unzips to the stream's sink (which is to simply unzip to a file in the filesystem).
    // 
    // 2) Create a stream object and call UnzipToStreamAsync.  This starts the unzip in a background
    //    thread (after Task.Run is called).  Your application can then read the unzipped (inflated) file
    //    directly from the stream.
    // 
    // 3) (not shown in this example) Unzip to a stream object that is the source of something else.
    //    

    // ----------------------------------------------------------------
    // Case 1: Unzip to a file by setting the sink of streamA to a file.
    Get Create (RefClass(cComChilkatStream)) To hoStreamA
    If (Not(IsComObjectCreated(hoStreamA))) Begin
        Send CreateComObject of hoStreamA
    End
    Set ComSinkFile Of hoStreamA To "qa_output/hamletA.xml"

    Get pvComObject of hoStreamA to vStreamA
    Get ComUnzipToStream Of hoEntry vStreamA To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEntry To sTemp1
        Showln sTemp1
        Send Destroy of hoEntry
        Procedure_Return
    End

    // Close the stream to close the output file.
    Get ComWriteClose Of hoStreamA To iSuccess

    // ----------------------------------------------------------------
    // Case 2a: Uzip to a stream asynchronously. 
    Get Create (RefClass(cComChilkatStream)) To hoStreamB
    If (Not(IsComObjectCreated(hoStreamB))) Begin
        Send CreateComObject of hoStreamB
    End

    Get pvComObject of hoStreamB to vStreamB
    Get ComUnzipToStreamAsync Of hoEntry vStreamB 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

    // Read the stream.  (this is reading the unzipped file data)
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    While ((ComEndOfStream(hoStreamB)) <> True)
        // Each call to ReadSb appends to the contents of sb.
        Get pvComObject of hoSb to vSb
        Get ComReadSb Of hoStreamB vSb To iSuccess
    Loop

    Get ComWriteFile Of hoSb "qa_output/hamletB.xml" "utf-8" False To iSuccess

    Send Destroy of hoUnzipTask
    Showln "Success."

    // ----------------------------------------------------------------
    // Case 2b: Uzip to a stream asynchronously and emit output while reading. 
    Get Create (RefClass(cComChilkatStream)) To hoStreamC
    If (Not(IsComObjectCreated(hoStreamC))) Begin
        Send CreateComObject of hoStreamC
    End

    Get pvComObject of hoStreamC to vStreamC
    Get ComUnzipToStreamAsync Of hoEntry vStreamC 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

    Get ComRun Of hoUnzipTask To iSuccess

    While ((ComEndOfStream(hoStreamC)) <> True)
        Get ComReadString Of hoStreamC To s
        Showln s
    Loop

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


End_Procedure

 

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