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

PowerBuilder 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

 

 

 

(PowerBuilder) Chaining Asynchronous Streams

The asynchronous functionality of Chilkat, combined with streams, can offer some interesting possibilities. This example demonstrates how to create two streams, call them streamA and streamB, where streamA feeds into streamB and both streams run in background threads. The examples demonstrates copying a file in this way:

sourceFile --> streamA --> streamB --> outputFile

This may seem pointless, but the possibilities become interesting when intermediate streams can perform tasks such as encryption or compression, or when a source or sink is a socket, a TLS connection, an SSH tunnel, etc. Or perhaps if a stream becomes the source for the file in an HTTP upload, or perhaps it is the source or sink for files in FTP, SFTP, etc. This is where Chilkat's Async standards in combination with Chilkat Stream can begin to offer powerful and simple-to-implement possibilities.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_StreamA
oleobject loo_StreamB
integer li_Success
oleobject loo_TaskA
oleobject loo_TaskB
oleobject loo_Fac
integer li_BFilesEqual

loo_StreamA = create oleobject
li_rc = loo_StreamA.ConnectToNewObject("Chilkat_9_5_0.Stream")
if li_rc < 0 then
    destroy loo_StreamA
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_StreamB = create oleobject
li_rc = loo_StreamB.ConnectToNewObject("Chilkat_9_5_0.Stream")

loo_StreamA.SourceFile = "qa_data/hamlet.xml"

// streamA will feed into streamB. (streamA is the source for streamB)
li_Success = loo_StreamB.SetSourceStream(loo_StreamA)

loo_StreamB.SinkFile = "qa_output/hamlet_copy.xml"

// Run each stream asynchronously in background threads:
loo_TaskA = loo_StreamA.RunStreamAsync()
loo_TaskB = loo_StreamB.RunStreamAsync()

// Start each task. (The call to Run returns immediately. 
// each task begins running in its own background thread.)
li_Success = loo_TaskA.Run()
li_Success = loo_TaskB.Run()

// Wait for each task to complete.
// Note: The SleepMs method is a utility method that puts the caller to sleep
// for a specified number of milliseconds.
// It is the caller's thread that sleeps (i.e. this foreground thread).
// It does not cause the background thread of the given task object to sleep.
do while ((loo_TaskA.Finished <> 1) OR (loo_TaskB.Finished <> 1))
    loo_TaskB.SleepMs(20)
loop

// At this point, each background task has finished. 
// Let's check to see if each stream succeeded.

// Did streamA succeed in reading the entire file?
if loo_TaskA.TaskSuccess <> 1 then
    Write-Debug "streamA failed:"
    Write-Debug loo_TaskA.ResultErrorText
    li_Success = 0
end if

// Did streamB succeed in writing the entire file?
if loo_TaskB.TaskSuccess <> 1 then
    Write-Debug "streamB failed:"
    Write-Debug loo_TaskB.ResultErrorText
    li_Success = 0
end if

if li_Success <> 1 then
    destroy loo_StreamA
    destroy loo_StreamB
    return
end if

// Let's double-check to see that the files are equal in size and content:
loo_Fac = create oleobject
li_rc = loo_Fac.ConnectToNewObject("Chilkat_9_5_0.FileAccess")

li_BFilesEqual = loo_Fac.FileContentsEqual(loo_StreamA.SourceFile,loo_StreamB.SinkFile)
if li_BFilesEqual <> 1 then
    Write-Debug "The output file is not equal to the input file!"
else
    Write-Debug "The file was successfully copied in a very roundabout way!"
end if



destroy loo_StreamA
destroy loo_StreamB
destroy loo_Fac

 

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