(Swift) Unzip Files to Byte Array
Demonstrates how to unzip each file contained in a .zip to an in-memory byte array.
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let zip = CkoZip()!
var success: Bool = zip.open("qa_data/zips/test.zip")
if success == false {
print("\(zip.lastErrorText!)")
return
}
// Iterate of each entry in the zip.
// An entry can be a file or directory entry. For each file, unzip to a byte array.
var numEntries: Int = zip.numEntries.intValue
print("NumEntries = \(numEntries)")
var i: Int = 0
while i < numEntries {
var entry: CkoZipEntry? = zip.getEntryByIndex(i)
if entry!.isDirectory == false {
var fileData: NSData = entry!.inflate()
// Do whatever you wish with the file data...
}
entry = nil
i = i + 1
}
zip.close()
print("Finished.")
}
|