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) Controlling Paths of Files Added to Zip

When appending files to a .zip, it can be difficult to get the paths exactly as you want them. This example describes a way that you can control the path information when adding a single file at a time to a .zip.

Chilkat Ruby Downloads

Ruby Library for Linux and MAC OS X

require 'chilkat'

zip = Chilkat::CkZip.new()

success = zip.UnlockComponent("anything for 30-day trial")
if (success != true)
    print "Failed to unlock zip component" + "\n";
    exit
end

#  Intialize the zip object by calling NewZip.
success = zip.NewZip("myZip.zip")

#  Add a reference to a file on disk to the zip object.
#  (When appending files to a zip, the files are not actually
#  read into memory.  References to the file(s) are added.
#  When WriteZip is called, the referenced files are streamed in
#  and compressed to the .zip.)
saveExtraPath = false
success = zip.AppendOneFileOrDir("/temp/a/hamlet.xml",saveExtraPath)
#  For brevity, this example will not check the return status...

#  The saveExtraPath argument, if set, will cause the path information
#  passed in the 1st argument to be saved in the .zip.

#  To add "a/hamlet.xml", do this:
zip.put_AppendFromDir("/temp")
#   The saveExtraPath argument, if set, will cause the path information
#   passed in the 1st argument to be saved in the .zip.     But the path in AppendFromDir is
#   not added to that path saved in the .zip.     If there is a path in AppendFromDir then the
#   path in the 1st argument must be relative, not preceded by a drive or \.
saveExtraPath = true
success = zip.AppendOneFileOrDir("a/hamlet.xml",saveExtraPath)

#  To add "temp/a/hamlet.xml", do this:
zip.put_AppendFromDir("/")
saveExtraPath = true
success = zip.AppendOneFileOrDir("temp/a/hamlet.xml",saveExtraPath)

#  The zip written here will contain hamlet.xml three times,
#  each with a different relative path.
success = zip.WriteZipAndClose()

 

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