Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaJavaScriptNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Swift Examples
Web API Categories

AI
ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Apple Keychain
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
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)
JavaScript
MHT / HTML Email
MIME
Markdown
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
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Swift) Add Text from a StringBuilder to a ZIP Using AddSb

See more Zip Examples

This example demonstrates how to use the AddSb method to add text from a StringBuilder object as a file entry within a ZIP archive.

The text is converted to bytes using the specified character encoding before being stored in the ZIP archive.

This method is useful for dynamically generating text files entirely in memory without creating temporary files on disk.

Chilkat Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

func chilkatTest() {
    var success: Bool = false

    let zip = CkoZip()!

    success = zip.newZip("stringBuilderData.zip")
    if success == false {
        print("\(zip.lastErrorText!)")
        return
    }

    // Create a StringBuilder containing text data.
    let sb = CkoStringBuilder()!

    sb.appendLine("Line 1: Hello World!", crlf: true)
    sb.appendLine("Line 2: This text came from a StringBuilder.", crlf: true)

    // Add the StringBuilder contents as a UTF-8 text file
    // stored in the ZIP archive as "docs/readme.txt".
    success = zip.addSb("docs/readme.txt", sb: sb, charset: "utf-8")
    if success == false {
        print("\(zip.lastErrorText!)")
        return
    }

    // Write the ZIP archive to disk and close it.
    success = zip.writeAndClose()
    if success == false {
        print("\(zip.lastErrorText!)")
        return
    }

    print("ZIP archive created successfully.")

}

 

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