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

Ruby Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)

Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Ruby) 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 Ruby Downloads

Ruby Library for Linux and MAC OS X

require 'chilkat'

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

zip = Chilkat::CkZip.new()

#  First open a .zip.
success = zip.OpenZip("qa_data/zips/big.zip")
if (success != true)
    print zip.lastErrorText() + "\n";
    exit
end

#  Get the entry to be unzipped to a stream..
# entry is a CkZipEntry
entry = zip.GetEntryByIndex(0)
if (zip.get_LastMethodSuccess() != true)
    print zip.lastErrorText() + "\n";
    exit
end

dataStream = Chilkat::CkStream.new()

# unzipTask is a CkTask
unzipTask = entry.UnzipToStreamAsync(dataStream)
if (entry.get_LastMethodSuccess() != true)
    print entry.lastErrorText() + "\n";

    exit
end

#  Start the background unzip thread.
unzipTask.Run()

#  We'll read the uncompressed data chunk-by-chunk and write to an output file.
fac = Chilkat::CkFileAccess.new()
success = fac.OpenForWrite("qa_output/out.dat")
if (success != true)
    print fac.lastErrorText() + "\n";

    exit
end

#  Read the stream.  (this is reading the unzipped file data)
bd = Chilkat::CkBinData.new()
while dataStream.get_EndOfStream() != true
    #  Get the next chunk of decompressed bytes.
    dataStream.ReadBd(bd)
    #  Do something with it..
    #  In this simple example, we'll just write to the file.
    fac.FileWriteBd(bd,0,0)
    #  Clear for the next read.
    bd.Clear()
end

fac.FileClose()

print "Success." + "\n";

 

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