使用SSZipArchive解压缩下载的zip文件



我用来下载这本书的代码是
//创建要下载的源文件的URLlet fileURL=URL(字符串:myFileURL(

let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL!)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil {
// Success
if let statusCode = (response as? HTTPURLResponse)?.statusCode {
print("Successfully downloaded. Status code: (statusCode)")
DispatchQueue.main.async {
self.toast(msg: "Download completed")
self.activityIndicator.stopAnimating()
self.activityIndicator.isHidden = true
}
}
do {
try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
} catch (let writeError) {
print("Error creating a file (destinationFileUrl) : (writeError)")
}
} else {
print("Error took place while downloading a file. Error description: %@", error?.localizedDescription);
}

之后,我尝试使用代码从destinationFileUrl解压缩epub文件

let status = SSZipArchive.unzipFile(atPath: destinationFileUrl , toDestination:destPath, delegate:self)

状态值返回false,因此输出文件夹只包含没有项目的META-INF文件夹

如何正确解压缩epub

请参阅此-->>解压缩下载的文件URL 后无法弹出文件

var filepath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
filepath += "/(UUID().uuidString)"
let url = URL(fileURLWithPath: filepath)
do {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
let done = SSZipArchive.unzipFile(atPath: path!, toDestination: url.path)
if done{
let items = try FileManager.default.contentsOfDirectory(atPath: url.path)
print(items)
}
} catch let error as NSError{
print(error)
}

相关内容

  • 没有找到相关文章

最新更新