gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:57:33 39 4
gpt4 key购买 nike

我用于下载这本书的代码是..
//创建要下载的源文件的URL 让 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

最佳答案

请引用此 -->> Not getting eject file after unzipping downloaded file 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)
}

关于swift - 使用 SSZipArchive 解压缩下载的 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53774650/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com