Swift
Swift
Unzip Text File to String
See more Zip Examples
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let zip = CkoZip()!
success = zip.open(zipPath: "qa_data/zips/EC16100.zip")
if success == false {
print("\(zip.lastErrorText!)")
return
}
// Get the 1st file in the .zip
let entry = CkoZipEntry()!
success = zip.entry(at: 0, entry: entry)
if success == false {
print("\(zip.lastErrorText!)")
return
}
var fileContents: String? = entry.unzip(toString: 0, srcCharset: "utf-8")
print("\(fileContents!)")
}