I download a .zip file from a URL in ViewControllerA, and put it in the documents directory using:
let documentsUrl:URL = (FileManager.default.urls(for: .documentDirectory, in: .allDomainsMask).first as URL?)!
let destinationFileUrl = documentsUrl.appendingPathComponent("zipFile.zip")
When i am trying to retrieve the file from ViewControllerB and unzipping it using:
let documentsUrl:URL = (FileManager.default.urls(for: .documentDirectory, in: .allDomainsMask).first as URL?)!
let destinationFileUrl = documentsUrl.appendingPathComponent("zipFile.zip")
do{
let file = try Zip.quickUnzipFile(destinationFileUrl)
}catch {
print("Error: \(error.localizedDescription)")
}
It is giving me an error:
Error: The operation couldn’t be completed. (Zip.ZipError error 1.)
But when i am trying it to do it in the same ViewController. i.e. If i am trying to download the file in ViewControllerA and unzip the file right away, it is working fine:
let documentsUrl:URL = (FileManager.default.urls(for: .documentDirectory, in: .allDomainsMask).first as URL?)!
let destinationFileUrl = documentsUrl.appendingPathComponent("zipFile.zip")
Downloader.load(url: remoteURL, to: destinationFileUrl, completion: {
print("Downloaded.")
do{
let file = try Zip.quickUnzipFile(destinationFileUrl)
}catch {
print("Error: \(error.localizedDescription)")
}
})
Things i have verified:
- Zip file exists in the document directory.
- Zip file has valid file size.
- Zip file has read and write permissions.
What is it that is preventing unzip process between two different ViewControllers?